0% found this document useful (0 votes)
15 views

Loop Statements

The document discusses different types of loop statements in C language - while, for, do-while loops. It also discusses nested loops, break, continue and goto statements used with loops. Some key points: - while loop repeats as long as a condition is true. - for loop executes a specific number of times. - do-while loop checks condition at the bottom, so it executes at least once. - Loops can be nested inside each other. - break stops the current loop. continue skips to next iteration. - goto provides unconditional jump but is discouraged due to readability issues.

Uploaded by

Adhiraj Kaushik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Loop Statements

The document discusses different types of loop statements in C language - while, for, do-while loops. It also discusses nested loops, break, continue and goto statements used with loops. Some key points: - while loop repeats as long as a condition is true. - for loop executes a specific number of times. - do-while loop checks condition at the bottom, so it executes at least once. - Loops can be nested inside each other. - break stops the current loop. continue skips to next iteration. - goto provides unconditional jump but is discouraged due to readability issues.

Uploaded by

Adhiraj Kaushik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

C Language

Loop Statements

Dr. A. Nayeemulla Khan


while loop
A while loop statement in
C programming language
repeatedly executes a target
statement as long as a given
condition is true.
for loop
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.
do...while
Unlike for and while loops, which test the loop condition at
the top of the loop, the do...while loop in C programming
language checks its condition at the bottom of the loop.

A do...while loop is similar to


a while loop, except that a
do...while loop is guaranteed
to execute at least one time.
nested loops

for ( init; condition; increment )


{
for ( init; condition; increment )
{
statement(s);
}
statement(s);
}
nested loops

while(condition)
{
while(condition)
{
statement(s);
}
statement(s);
}
nested loops
do
{
statement(s);
do
{
statement(s);
}while( condition );
}while( condition );
break statement

The break statement in C programming language has the


following two usages:
1. When the break statement is encountered inside a loop,
the loop is immediately terminated and program control
resumes at the next statement following the loop.
2. It can be used to terminate a case in the switch statement

If nested loops are in use (i.e., one loop inside another


loop), the break statement will stop the execution of the
innermost loop and start executing the next line of code after
the block.
break statement
continue statement

The continue statement in C programming language works


somewhat like the break statement. Instead of forcing
termination, however, continue forces the next iteration of
the loop to take place, skipping any code in between.

For the for loop, continue statement causes the conditional


test and increment portions of the loop to execute.

For the while and do...while loops, continue statement


causes the program control passes to the conditional tests
continue statement
goto statement

A goto statement in C programming language provides an


unconditional jump from the goto to a labeled statement in
the same function.

NOTE: Use of goto statement is highly discouraged in any


programming language because it makes difficult to trace
the control flow of a program, making the program hard to
understand and hard to modify. Any program that uses a
goto can be rewritten so that it doesn't need the goto.
goto statement

You might also like