0
why i can't break 'if-else' statement?
8 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.
+ 1
give us some code sample please
+ 1
aditya return;
+ 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 ;)
0
Damyan Petkov just try ...i think ide will give you error
0
James then what should i do to come out of 'if else' statement?