En Course Loops
En Course Loops
Mohamed MESSABIHI
[email protected]
University of Tlemcen
Department of Computer Science
https://sites.google.com/site/informatiquemessabihi/
Some Examples Before We Begin!
Exercise
while ( Condition )
{
// Block of instructions
}
Example:
int p osi ti ve I nt eg e r = 0;
while ( p os it i ve In t eg er <= 0)
{
printf ( " Enter a positive integer : " ) ;
scanf ( " % d " , & p o si ti v eI n te ge r ) ;
}
Repeating a Specific Number of Times
int counter = 0;
Infinite loops occur when the number of iterations in a ‘while‘ loop is not
known in advance. It depends on the condition evaluation.
Make sure your loops can terminate at some point. If the condition
always remains true, your program will run indefinitely!
One of the instructions inside the loop must change the condition from
true to false after a certain number of iterations.
Example:
int counter = 0;
do
{
// Block of instructions
} while ( Condition ) ;
Here’s an example using a ‘do...while‘ loop to print the variable ‘n‘ from
0 to 9.
Example:
int n = 0;
do
{
printf ( " The variable n is % d \ n " , n ) ;
n ++;
} while ( n < 10) ;
The "for" Loop
Here’s an example using a ‘for‘ loop to print the variable ‘i‘ from 0 to 9.
Example:
Loop control statements allow you to modify the flow of loop execution:
• ‘break‘: Terminates the loop and transfers control to the statement
following the loop.
• ‘continue‘: Skips the current iteration and jumps to the next
iteration of the loop.
These statements can be used in ‘for‘, ‘while‘, and ‘do...while‘ loops.
"break" Statement
The ’break’ statement can be used to exit a loop prematurely.
Example:
The For loop is a specific case of the While loop (in cases where the
number of iterations is known and fixed). Everything that can be written
with For can be replaced by a While loop (the reverse is not necessarily
true).
Example:
for ( int i = 0; i < 10; i ++)
{
if ( i == 5)
{
continue ; // skip iteration when i equals 5
}
printf ( " The variable i is % d \ n " , i ) ;
}
Nested Loops
The block of instructions in one loop can itself contain another loop.
These are called nested loops.
Example:
int i ;
int j =1;
for ( i = 1 ; i <= 3 ; i ++)
{
j =1
while ( j <= 4)
{
printf ( " i =% d and j =% d !\ n " , i , j ) ;
j ++;
}
}
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Nested Loops
Execution History
Inst. i j Affichage
1 1 1 i=1 et j=1
2 1 2 i=1 et j=2
3 1 3 i=1 et j=3
4 1 4 i=1 et j=4
5 2 1 i=2 et j=1
6 2 2 i=2 et j=2
7 2 3 i=2 et j=3
8 2 4 i=2 et j=4
9 3 1 i=3 et j=1
10 3 2 i=3 et j=2
11 3 3 i=3 et j=3
12 3 4 i=3 et j=4
Which Loop Should I Use for My Program?
The choice between these loops depends on the specific problem you are
solving and the control flow you want in your program. If you are unsure
which loop to use, consider the following questions:
Ultimately, the best loop for your C program depends on your program’s
specific logic and requirements.
Which Loop Should I Use for My Program?
The choice between these loops depends on the specific problem you are
solving and the control flow you want in your program. If you are unsure
which loop to use, consider the following questions:
Ultimately, the best loop for your C program depends on your program’s
specific logic and requirements.
Which Loop Should I Use for My Program?
The choice between these loops depends on the specific problem you are
solving and the control flow you want in your program. If you are unsure
which loop to use, consider the following questions:
Ultimately, the best loop for your C program depends on your program’s
specific logic and requirements.
Which Loop Should I Use for My Program?
The choice between these loops depends on the specific problem you are
solving and the control flow you want in your program. If you are unsure
which loop to use, consider the following questions:
Ultimately, the best loop for your C program depends on your program’s
specific logic and requirements.
Which Loop Should I Use for My Program?
The choice between these loops depends on the specific problem you are
solving and the control flow you want in your program. If you are unsure
which loop to use, consider the following questions:
Ultimately, the best loop for your C program depends on your program’s
specific logic and requirements.
Which Loop Should I Use for My Program?
The choice between these loops depends on the specific problem you are
solving and the control flow you want in your program. If you are unsure
which loop to use, consider the following questions:
Ultimately, the best loop for your C program depends on your program’s
specific logic and requirements.
Examples to Conclude ...
Example with While Loop: