can anybody give me a link or anything that can help me understand switch loops a little bit more im a newbie to C++ so any help wud be highly appreciated

Recommended Answers

All 2 Replies

What do you mean by "switch loop"?
1) Switch and loop
2) Loop in switch
3) Switch in loop
4) or is it "Switch loop"

Try switch loop

int n;

// Assign n some value //

switch (n) {
case 0:
 cout << "n = 0";
 break;
case 3:
 cout << "n = 3";
 break;
case 7:
 cout << "n = 7";
default:
 cout << "n is not 0, 3, or 7."
 break;
}

The case statements are checks, if the value specified is true.
The default statement is the one which will go when the cases are NOT true.
Every block must end with break, so that the loop will end.

This is exactly the same code as the switch block above:

int n;

// Assign n some value //

if (n == 0)
 cout << "n = 0";
else if (n == 3)
 cout << "n = 3";
else if (n == 7)
 cout << "n = 7";
else
 cout << "n is not 0, 3, or 7."
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.