Download presentation
Presentation is loading. Please wait.
Published byAnabel Leonard Modified over 6 years ago
1
The nested repetition control structures & Continue Statements
2
What is nested loop?? A loop inside the body of another loop is called nested loop. The loop that contains another loop in its body is called outer loop. The loop used inside the body of outer loop is called inner loop.
3
Syntax Outer loop { statements; Inner loop body of inner loop }
4
Flowchart of nested loop
condition for outer loop False True Condition for inner loop False True Body of inner loop
5
Example void main() { int u, i; u=1; while (u<=3) printf(“%d”); for(i=1; i<=2; i++) printf(“I love pakistan”); u= u+1; }
6
Infinite loop sometimes called an endless loop
Infinite loop is a piece of coding that lacks a functional exit so that it repeats indefinitely. Usually, an infinite loop results from a programming error for example, where the conditions for exit are incorrectly written. Intentional uses for infinite loops include programs that are supposed to run continuously.
7
The continue statement
The continue statement can be used in the body of any loop structure. statement is executed, it skips the remaining of loop.
8
Syntax & Example Syntax: continue; Example: int x=1; do {
printf(“Welcome”); ++x; printf(“Karachi”); }while (x<=5);
9
void main() { int u, i; for(u=5; u>=1; u--) for(i=1; i<=u; i++) { printf(“*”); } printf(“\n”); } getch();
10
Program task1… Write a program that displays the following output using the nested for loop. ***** **** *** ** *
11
Program task2… Write a program that displays the following output using the nested for loop.
12
void main() { int u, i; u=1; while(u>=5) i=1; while(i<=u) printf(“%d\t”, u*i++); u++; } getch();
13
Program task3… Write a program that displays the following output using the nested for loop. 1 1 4 1 4 9
14
void main() { int u, i; u=1; while(u<=5) i=1; while(i<=u) printf(“%d\t”, i*i); i++; } printf(“\n”); u++; getch();
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.