--Séquentiellement
--Branche
- if
, switch
--Répéter
- while
,for
if
switch
//si syntaxe
int r=new java.util.Random().nextInt(2);
if (r<1){
System.out.println("This is true by 'if'.");
}else{
System.out.println("This is false by 'if'.");
}
//syntaxe de commutation
int s=new java.util.Random().nextInt(3);
switch(s){
case 0:
System.out.println("This is Case.0 by 'switch'.");
break;
case 1:
System.out.println("This is Case.1 by 'switch'.");
break;
case 2:
System.out.println("This is Case.2 by 'switch'.");
break;
default:
System.out.println("This is default by 'switch'.");
}
while
do while
for
//tandis que la syntaxe
int w=1;
while(w<4){
System.out.println("Count No."+w+" by 'while'.");
w++;
}
//faire tout en syntaxe
int dw=3;
do{
System.out.println("Count No."+dw+" by 'do while'.");
dw--;
System.out.println("Count decrease -1 by 'do while'.");
}while(dw>0);
//pour la syntaxe
for(int i=1; i<=3; i++){
System.out.println("Count No."+i+" by 'for'.");
}
-- continue
: continue la boucle.
--break
: Sortez de la boucle.
//Interruption répétée
for(int i=5; i>=1; i--){
if(i==3){
continue;
}
if(i==2){
break;
}
System.out.println("Count No."+i+" by 'for/continue(3)/break(2)'.");
}
[Introduction à Java 2nd Edition] (https://www.amazon.co.jp/dp/B00MIM1KFC/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1) Pp.098-133.
Recommended Posts