Lesson 7


                          Control Flow - Looping

1. while Statement

2. do while Statement

3. for Statement

4. break Statement

5. continue Statement

6. goto Statement

1. while Statement

A while loop in C programming repeatedly executes a target statement as long as a given condition is true.

Syntax

The syntax of a while loop in C programming language is −

while(condition) {

   statement(s);

}

Flow Diagram

2.Do while Statement

Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop in C programming checks its condition at the bottom of the loop.A do...while loop is similar to a while loop, except the fact that it is guaranteed to execute at least one time.

Syntax

The syntax of a do...while loop in C programming language is −

do {

   statement(s);

} while( condition );

Flow Diagram

3.For Statement

A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.

Syntax

The syntax of a for loop in C programming language is −

for ( init; condition; increment ) {

   statement(s);

}

Flow Diagram

4. Break Statement

The break is a keyword in C which is used to bring the program control out of the loop. The break statement is used inside loops or switch statement. The break statement breaks the loop one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops. The break statement in C can be used in the following two scenarios:

1. With switch case

2. With loop

Syntax:

1. //loop or switch case

2. break;

Flowchart of break in c

5.Continue Statement

The continue statement in C language is used to bring the program control to the beginning of the loop. The continue statement skips some lines of code inside the loop and continues with the next iteration. It is mainly used for a condition so that we can skip some code for a particular condition.

Syntax:

1. //loop statements

2. continue;

3. //some lines of the code which is to be skipped

6.Goto Statement

When a goto statement is encountered in a C program, the control jumps directly to the label mentioned in the goto stateemnt

Syntax of goto statement in C

goto label_name;

..

..

label_name: C-statements

Flow Diagram of goto


Popular posts from this blog

LESSON 1