Objective C Loops - Objective C

What are Objective C Loops?

  • Loops are used when a block of code need to be executed several number of times.
  • The statements are executed sequentially. The first statement is executed first followed by the second and so on.
  • Various control structures are provided by the programming languages for complicated paths.
  • To execute a statement or group of statements multiple times, loop statement is used.

General form of loop statement is depicted below:

Objective C loop architecture

The following types of loops to handle the looping requirements are given below:

Loop Type
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 and abbreviates the code that manages the loop variable.
do...while loop
Like a while statement, except that it tests the condition at the end of the loop body.
nested loops
You can use one or more loops inside any another while, for or do..while loop.

Loop Control Statements

The execution changes from the normal sequence. The objects in the scope are destroyed when the execution leaves a scope.

Control Statement
break statement
Terminates thelooporswitchstatement 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.

The Infinite Loop

If a condition never becomes false, then the loop becomes false. The loop can be made endless by leaving the conditional expression empty.

It is assumed to be true , when there is no conditional expression. Objective C programmers use (; ; ) construct to signify the infinite loop.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Objective C Topics