The loop are used to repeat the execution of statement of block loop are used to perform a set of instruction repeatedly this involves repeating some partition of the program.

There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially. The first statement in a function is executed first, followed by the second, and so on. Programming languages provide various control structures that allow for more complicated execution paths.

A loop statement allows us to execute a statement or group of statements multiple times and following is the general from of a loop statement in most of the programming languages:

1. While loop

2. Do ... While loop

3. For loop


While loop

The while loop is used when the number of iteration to be performed are not known in advance. A while loop statement repeatedly executes a target statement as long as a given condition is true.

Syntax -

Initialization;

    While(condition)

{

    True statement;

}

False statement;


Do … While

In the case the code within the block is executed at least one time the condition for iteration of the loop is checked at the end it is also known as entry control loop. A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.

Syntax -

Initialization;

    Do

{

    statement;

}

While (condition);


For loop

The for loop is used to execute a statement a fixed number of times more than one statement can be placed in the block it has 3 part Initialization; loop condition; increment and decrement

Syntax -

For (Initialization; condition; increment/decrement)

{

    statement;

}


Loop Control Statements


Break Statement

The statement causes unconditional exit from for while do while if else or switch statement immediately outside the block in which break appear.

Syntax –

Break;


Continue Statement

The continue statement causes conditional transfer to the next iteration in a for while do for statement the control is transfer to the statement begin of the block in which continue appear.

Syntax –

Continue;


Goto Statement

The statement causes unconditional transfer to statement marked with the label within the function the label is marked with a unique many or number followed by a colon and a statement.

Syntax -

goto label;

    ..

    .

label: statement;