Misplaced Break/Misplaced Continue
Have you ever tried placing break or continue in if/else blocks of the code?
Actually We can't place break or continue in if/else block.If we place them then compiler will throw an error saying that misplaced break or misplaced continue.
The immediate question encountered in our minds is that 'do we have any scenario where we can place the break/continue in if/else blocks?'.
Answer is yes,we can place them only if that if/else block is in a loop. We can use break/continue only in loops.
In the same way, we have one interesting case with ternary/conditional operator. We all know that we can replace simple if-else with ternary operator in some specific cases.
Have you ever noticed what happens if we place a return statement in ternary/conditional operator (?:). In this case also compiler throws an error saying that it is an Expression Syntax Error.
0 comments:
Post a Comment