In computer programming, a loop is a sequence of instructions that is continually repeated until a certain condition is reached. Typically, certain process is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number. If it hasn’t, the next instructions in the sequence is an instruction to return to the first instruction in the sequence and repeat the sequence. If condition has been reached, the next instructions “falls through” to the next sequential instruction or branches outside the loop. A loop is a fundamental programming idea that is commonly used in writing programs. There are three types of loop.
While loop
For loop
Do while loop
1.While loop syntax:
Initialization expression;
While( termination condition)
{
statements;
increment / decrement;
}
For loop syntax;
2.For(initialization expression; termination condition; increment/decrement)
{
body of the loop;
statements;
}
3. Do while loop syntax:
Initialization expression;
do{
Statements;
Increment/decrement;
}while(termination condition);
4. Nested loop syntax:
For(initialization expression;condition; inc / dec)
{
for(initialization exp;condition; inc / dec)
{
statements;
}
}
1st for loop is called outer loop and next for loop is called inner loop.
mail address: [email protected]