You are on page 1of 8

Loop

In Previous Class
● Control Structure
Iteration statements in C
● One of the Control Statements which used for repetitive statements.

● Iteration statements change execution from its normal sequence.

● Iteration statements cause statements (or compound statements) to be

executed zero or more times, subject to some loop-termination criteria.

● When execution leaves a scope, all automatic objects that were created in

that scope are destroyed.


Why Loop?
● Loops in programming come into use when

we need to repeatedly execute a block of

statements.

● Example: Writing a table of 9.


Loop
● 3 types of iteration statements:

○ for loop
Entry Controlled
○ while loop

○ do while loop Exit Controlled


Loop Basic Elements
● Initialization Expression

○ Initializing the the loop counter

● Test Expression

○ Set a condition for running the block

● Update Expression

○ Update the loop counter/variable


Loop
● Start from initialization
● Check Condition
● Execute the body of the loop if Condition
is True, else exit from loop
● End with updating the loop variable
Syntax

for (initialization_expr; test_expr; update_expr)


{
// body of the loop

// statements we want to execute


}

You might also like