Loop Statement Programs






 " In computer programming, a loop is a sequence of instruction that is continually repeated until a certain condition is reached "



There are three types of loops

for loop
while loop
do while loop





FOR LOOP


Defination

- For loop is used for counting purpose.
- For loop is divided into three parts
1- initialization
2-  condition
3- increment/decrement

Initialization is that part of the loop where counting starts.
Condition is that part of the loop which defines the end point of the counting till it satisfy the parameter(condition)
Increment/Decrement is that part of the loop which defines the order of counting in increment/decrement order.


Syntax of for loop

for(initialization; condition; increment/decrement)
{
Statements ;
}


Programming (Example)


Ques - Display the number from 0 to 9 using for loop




Output







WHILE LOOP


- WHILE loops are very simple.
- If conditions is true the only it execute.


Syntax for while loop

while(condition)
{
statement1;
statement2;
.
.
statement n;
}

Program (Example)

Ques - Display the number from 0 to 9 using while loop




Output







DO WHILE LOOP


-DO..WHILE loop is very simple and useful 
-It execute at least once.


Syntax for do-while

do
{
Statements;
}while(condition);


Program(Example)





Output








By - Somesh Sah




Comments

Popular posts from this blog

Include Vs Import

Object Oriented Program (Paradigm)

Operators and Expressions