c looping statements tutorial

Bodhak c looping statements tutorial now we are going to learn with syntax’s and examples about Iterative Statements(Loops), Working with while loop, Working with for loop, Working with do..while.

LOOPING CONTROL STATEMENTS: Looping Control statements execute the selected group of the statement(s) repeatedly. 

The selected group of statements executed repeatedly depends on the given expression.

 

 

c looping statements tutorial:-

while Statement:

while is a control statement that we use to execute a set of statements repeatedly depending upon the outcome of a test.

Syntax :

while(expression)

{

statements;

}

the statements are executed until the expression becomes zero(false)

 

for Statement:

for is a control statement and we use it to create a loop of iterative operations.

Syntax :

for(exp1;exp2;exp3)

Statement;

The statement is executed until the expression expression2 becomes zero(false).

The expression exp1 is evaluated only once in the beginning and expression3 is evaluated at the end of every iteration.

do while Statement:

do is a control statement that creates a loop of operations. We use it with another keyword while

syntax:

do{

statements;

}while(expression);

The loop is terminated when expression becomes zero(false);

The do while is executed at least once irrespective of the expression is true or false

 

break Statement:

the break is a statement that terminates an innermost loop or switch.

We can not use break statement outside of loop or switch case.

break statement can be used with a loop(while, do-while, for) statements & switch-case statement

syntax :

while <expression>

{

st 1;

st 2;

break;

st 3;

st 4;

}

continue statement:

We use continue statement to bypass the remainder of the current pass through a loop.

The loop does not terminate when a continue statement is encountered. Rather, the remaining loop statements are skipped and the computation proceeds directly to the next pass through the loop.

syntax :

while <expression>

{

st 1;

st 2;

continue; st 3;

st 4;

}

We use break and continue statements along with while, do-while, for statements.

while using the break and continue statements programmer need to understand first the implementation of this statements.