0

why i can't break 'if-else' statement?

8th Apr 2018, 5:34 PM
aditya
aditya - avatar
6 Answers
+ 6
If breaks were used in an if statement like this: if (true) { doSomething(); break; doSomeOthers(); } else { break; } it would be identical to: if (true) doSomething(); so it doesn't help or change anything being able to put a break statement in there. This is also ignoring the fact that to use a break within a loop it is almost always placed within an if statement so the compiler wouldn't be able to tell which statement you were trying to break.
8th Apr 2018, 5:54 PM
John Wells
John Wells - avatar
+ 1
give us some code sample please
8th Apr 2018, 5:38 PM
Damyan Petkov
Damyan Petkov - avatar
+ 1
aditya return;
8th Apr 2018, 5:47 PM
Damyan Petkov
Damyan Petkov - avatar
+ 1
once the entire code within the respective block is met, the if statement is done, and no other block within the if-else will be executed. you can always use goto in languages that support it though ;)
8th Apr 2018, 9:11 PM
hinanawi
hinanawi - avatar
0
Damyan Petkov just try ...i think ide will give you error
8th Apr 2018, 5:41 PM
aditya
aditya - avatar
0
James then what should i do to come out of 'if else' statement?
8th Apr 2018, 5:47 PM
aditya
aditya - avatar