Programming Loops

Control Structure

we control the execution of statementit's of two types

1. looping str :

             a statment will go again & again

                        a. for

                        b. while

                        c. do while

2. selection str :

            divide a str n two sections & then execute one

                        a. if

                        b. switch

Loops:

            loop  s an instructions/ gp of inst that comp execute repeatedly to a specified num of time

FOR:::::

for(expr1; ecpr2; expr3;)

for (intitialize ; condition; expression)

all expr r ooptioanal but for must have the semnicolon ;

EXAMPLE:

WHILE

while (condition)

{one or more c++ statements}

Difference B/W For & While

when we already know tha nub of execution then we use for loop other wise while

for loops r knoen as determine loops e,g display shahid 5times

but while loops r knoen as undetermine loop e,g compute the sum of numbers untill we get 99

EXAmples

DO WHILE

do {one or more C++ stat}while (condition);

Difference  B/W  Do While & While

unlike while loop tha loop condition of do while loop must be followed by a semicolen

in while if condition is false loop will not execute but n do while even if condition s false the loop will execute at least onece

for & while r pretested loop but do while is a post tested loop.

Nested Loop

a loop wth in another loop s known as nested loop

     for(int i=1; i<=5; i++)

            for(int j=1; j<=4;  j++)

            cout <<i+j <<endl;

CONDITIONS::::

inner loop must begin & end wth in outer loop

one outer loop can have 16 inner loop if inner loop crosses the boundary of outer loop such errors r not detected by compiler known as sementic errors(meaninng errors)