+ 10

What is the error in this code?

int age = 22; switch(age) { case 16: Console.Write("y"); break ; default: Console.Write("o"); }

7th Feb 2018, 11:29 AM
Ali Abdulbasit
Ali Abdulbasit - avatar
5 Answers
+ 3
You are missing break; after default case.
7th Feb 2018, 11:34 AM
Sad
Sad - avatar
+ 4
the Switch Statement is Not a loop. After the write it will quit the brackets. it is not wrong, just Not necessary. are there any security issues when you keep it away? the Switch Statement is just a nested if-else-structure
7th Feb 2018, 6:13 PM
I. Stark
I. Stark - avatar
+ 3
I am confused. Where is the difference? And Why?
7th Feb 2018, 5:59 PM
I. Stark
I. Stark - avatar
+ 3
He is missing break; statement and break tells block of code to stop. Otherwise it can't get out of switch statement.
7th Feb 2018, 6:01 PM
Sad
Sad - avatar
+ 3
He should write break; like this: Console.write("o"); break;
7th Feb 2018, 6:04 PM
Sad
Sad - avatar