looping in c

6
LOOPS

Upload: prabhu-govind

Post on 13-Dec-2014

48 views

Category:

Education


5 download

DESCRIPTION

Looping in C in S-Teacher

TRANSCRIPT

Page 1: Looping in C

LOOPS

Page 2: Looping in C

FOR LOOP

The syntax of for loop isfor(initialisation;condition checking;increment){

set of statements}

The Example for for loop:// Program to print Hello 10 timesfor(i=0;i<10;i++){

printf(“Hello”);}

Page 3: Looping in C

WHILE LOOP The syntax for while loopwhile(condition){

statements;}

Page 4: Looping in C

Example for while loop:a=10;while(a != 0){

printf(“%d/t”,a);a- -;

}Output: 10 9 8 7 6 5 4 3 2 1

Page 5: Looping in C

DO WHILE LOOP The syntax of do while loopdo{

set of statements}while(condition)

Page 6: Looping in C

Example of do-while loop:i=10;do{

printf(“%d/t”,i);i--;

}while(i!=0)

Output:10 9 8 7 6 5 4 3 2 1