-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTracerFor.java
More file actions
25 lines (21 loc) · 800 Bytes
/
TracerFor.java
File metadata and controls
25 lines (21 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
Dans Python Tutor, tracer le programme suivant en utilisant le bouton "Next >"
1. Pourquoi pensez-vous que la boucle "for" est utilisée quand on connaît le nombre
exact de fois qu'on doit répéter une action (au lieu d'une boucle "while") ?
*/
public class TracerFor {
public static void main(String[] args) {
int i = 0;
System.out.print("While :\n\t");
while ( i < 3 ) {
System.out.print( i + " " );
i++;
}
System.out.println("après : " + i );
System.out.print("For :\n\t");
for ( int j = 0; j < 3; j++ ){
System.out.print(j + " ");
}
// System.out.println( "après : " + j ); // ne fonctionne pas -> j est seulement défini dans le bloc for{}
}
}