8_Objective-C Loops

Some times we  need to execute a block of code several number of times.

In general, statements are executed sequentially.

A loop statement allows us to execute a statement or group of statements multiple times.

Types of loops

  • while loop
  • for loop
  • do…while loop

While loop

  • Repeats a statement or group of statements while a given condition is true.
  • It tests the condition before executing the loop body.




For loop

  • Execute a sequence of statements multiple times
  • abbreviates the code that manages the loop variable.


for ( init; condition; increment )


Do…while loop

  • Like a while statement
  • Except that it tests the condition at the end of the loop body.



}while( condition );


Loop Control Statements:

Loop control statements change execution from its normal sequence.

  • break statement : Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.


  • continue statement : Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.


Relational & Logical Operators

In chapter of Objective-C Operators we give some discripe of Relational & Logical Operators but without examples because the examples base on Objective-C Decision Making

Example of Relational Operator

Example of Logical Operator

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s