Online Test Banks
Score higher
See Online Test Banks
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

Control Statements and Loops in Objective-C

Part of the Objective-C Programming For Dummies Cheat Sheet

In programming, as in life, you have to make decisions and act on them. Objective-C provides control statements and loops to help your program take action. You may want to repeat a set of instructions based on some condition or state, for example, or even change the program execution sequence. Here is the basic syntax for Objective-C control statements and loops.

if else

if (condition) {
  statement(s) if the condition is true;
else {
  statement(s) if the condition is not true;


for (counter; condition; update counter) {
  statement(s) to execute while the condition is true;

for in

for (Type newVariable in expression ) {
Type existingVariable ;
for (existingVariable in expression) {
  • *Expression is an object that conforms to the NSFastEnumeration protocol.

  • An NSArray and NSSet enumeration is over content.

  • An NSDictionary enumeration is over keys.

  • An NSManagedObjectModel enumeration is over entities.


while (condition) { 
  statement(s) to execute while the condition is true 

do while

do {
  statement(s) to execute while the condition is true 
  } while (condition);

Jump statements

return ;

Stop execution and return to the calling function.


Leave a loop.


Skip the rest of the loop and start the next iteration.

goto labelName;

An absolute jump to another point in the program (don't use it).


Terminates your program with an exit code.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus

Inside Sweepstakes

Win an iPad Mini. Enter to win now!