Continue, Break, Simple if and Compound if Statement, Loop and Its Types, For, While, Do-while loop, Nested loop

Continue, Break, Simple if and Compound if Statement, Loop and Its Types, For, While, Do-while loop, Nested loop

Continue, Break, Simple if and Compound if Statement, Loop and Its Types, For, While, Do-while loop, Nested loop

To view other topics related to Computer. Click Here.

Continue statement: -

The “continue” statement shifts the control break to the beginning of the loop. It is used inside the body of a loop. When this statement is executed inside the body of loop, the control shift to the first statement of the body of the loop and the statement within the body of loop following the continue statement are not executed. Its syntax will be as:

Continue;

Break statement: -

The “break” statement is used to terminate execution of a loop when it is used inside the body of the loop.

Different between continue and break statement:

The “break” statement terminates the loop during execution. The other statements of the body of the loop that come under the “break” statement are not executed.

The “continue” statement does not terminate the loop but it shifts the control at the beginning of the body of the loop. The statements of the body of the loop that come under the “continue” statement are not executed.

Simple if statement: -

It is a conditional statement. Ifs syntax will be as:

If (condition)

Statement;

So first of all condition is checked if it will become true then statement will be executed otherwise not.

For example

If (a>b)

Great = a;

Compound if statement: -

Its syntax will be as:

If (condition)

{

Statement 1;

Statement 2;

------------

}

Loop: -

A cycle process to called loop. Or if some kind of task is required more then one times then we use loop.

Types of loop: -

In C language there are three types of loop.

(1) For loop (2) While loop (3) Do-while loop

(1) For loop: -

If the number of cycles or repetition is already known then we use for loop.

Its syntax is:

For (variable = initial value; condition; increment or decrement ;)

{

Body of loop

}

So in the above structure first of all the value is initialized in the given variable, then in the second part that value is checked in the given condition, it is prove that body will process and if it is will become false then body of loop will not process in the tired part the value in variable is increment or decrement and then it is again checked in the condition part.

(2) While loop: -

The numbers of cycles or repetitions or iterations are already not known then we use while loop.

The syntax is:

While (condition)

{

Body of loop

}

So in this loop, first of all condition is checked, if it remains true the body of loop will process otherwise it will be stopped.

(3) Do-while loop: -

It is also a conditional loop like while loop, but in this loop condition is checked in the end, where as in the whole loop condition is checked first.

Its syntax will be as:

Do

{

Body of loop

}

While (condition);

So in this loop the body of loop will be processed one time at any case, whether the condition is true or false.

Nested loop: -

When one loop is enclosed with in other loop, then this kind of loop is called nested loop.

It may be a nested loop for loop.

It may be a nested while loop.

It may be nested do while loop.

If it is nested for loop then its syntax will be as:

For (variable 2 = initial value; condition; increment \ decrement)

{

For (variable 2 = initial value; condition; increment \ decrement)

{

} body of loop

}

}

The start loop is called outer loop and the end loop is called inner or internal loop. For each number of outer, the inner loop completes its whole cycle.

Post a Comment

Previous Post Next Post