looping statements( theory)

 Loops are block of codes which executes themselves again and again until the condition is true

There are two types of loops 

1. Entry controlled loop: these loops first check the condition before the statement of execution are known as entry controlled loop -means in these condition is checked then according to the condition the output is displayed.

There are two types of entry controlled loops:

1. For loop: it is the first to come as loop with one drawback. that it declare all the conditions and operator at its initialization. so if multiple subprograms are linked with it changing its condition or operator will affect them alot.

Syntax:

                for( initial condition; termination condition; operator)

                    {

                         O/P statements;

                    }

2. While loop: it is the 2nd loop to come in existance, it works with pre and post increment.

Syntax:        pre-increment.

                while(termination condition)

                    {

                        operator; 

                        O/P statements;

                    }

                     post-increment.

                while(termination condition)

                    {

                        O/P statements;

                        operator; 

                    }

2. Exit controlled loop: these loops first execute the statements then check the condition are known as exit controlled loop -means in these condition is checked after executing the statements once since the conditions are at bottom.

1. Do-While loop: it is the 3rd loop to come in existance, it works with pre and post increment too. it will execute the instruction once.

Syntax:        pre-increment.

                do

                    {

                        operator; 

                        O/P statements;

                    }

                    while(termination condition);

                     post-increment.

                do

                    {

                        O/P statements;

                        operator; 

                    }

                    while(termination condition);

Nesting of loops: in this concept the loop exists within the loop. In this way the loops are used to check the rows and columns. loop within loop is used in programs to check the multiple functions.

Syntax:

nesting of for loop

                 for( initial condition; termination condition; operator)

                    {

                             for( initial condition; termination condition; operator)

                            {

                             O/P statements;

                            }

                         O/P statements;

                    }

No comments:

Post a Comment