Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I "break"/"continue" in a while loop in objective-c?

can I "break"/"continue" in a while loop in objective-c?

(or are these reserved only for for loops)

like image 285
Greg Avatar asked May 07 '11 22:05

Greg


People also ask

How do you break a loop in Objective C?

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.

Can you break a while loop in C?

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.

Can we use break and continue in while loop?

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.

Can you break from a 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.


2 Answers

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.

like image 125
Michael Burr Avatar answered Oct 21 '22 06:10

Michael Burr


Yes of course you can! Give it a try!

like image 40
Fran Sevillano Avatar answered Oct 21 '22 07:10

Fran Sevillano