Professional Documents
Culture Documents
Loop in C
Loop in C
– for loop
– while loop
– do while loop
1 + 2 + 3 + 4 + 5 + 6 = 21
for loop
• Code:-
5 x 4 x 3 x 2 x 1 = 120
for loop
• Code:-
– Condition: Condition in while loop is must. The loop will repeatedly check the
condition. If condition found true, for loop will execute again.
– After printing Hello World, i will be incremented and will check the
condition again. If it is true, same thing will repeat.
while loop
• Problem statements-3:
5 + 1 + 6 = 12
while loop
• Code:-
• Declared 3 variables .
• Hence answer = 8
while loop
• What will be the result:-
int i = 0;
while(i<5)
{
printf(“Hello world”);
}
• It is an infinite loop.
• Loop variable i is remain 0.
• So, the loop condition is always true.
while loop
• What will be the result:-
int i = 0;
while( )
{
printf(“Hello world”);
i++;
}
• It is a syntactical error.