can I "break"/"continue" in a while loop in objective-c?
(or are these reserved only for for loops)
If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.
break command (C and C++)The break command allows you to terminate and exit a loop (that is, do , for , and while ) or switch command from any point other than the logical end. You can place a break command only in the body of a looping command or in the body of a switch command.
The break and continue statements are the jump statements that are used to skip some statements inside the loop or terminate the loop immediately without checking the test expression. These statements can be used inside any loops such as for, while, do-while loop.
Breaking Out of While Loops. To break out of a while loop, you can use the endloop, continue, resume, or return statement. endwhile; If the name is empty, the other statements are not executed in that pass through the loop, and the entire loop is closed.
From Apple's Objective-C docs:
Objective-C is defined as a small but powerful set of extensions to the standard ANSI C language.
So break
and continue
can be used wherever they are permitted in C.
continue
can be used in looping constructs (for
, while
and do/while
loops).
break
can be used in those same looping constructs as well as in switch
statements.
Yes of course you can! Give it a try!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With