0

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

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by hiddepolen
0
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."
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.