for(initialization, expression, increment)
for(int i = 0 ; i < 10 ; i++)输出:
System.out.println(i);
0表达式的三个是可选的, 无限循环的创建方式如下:
1
2
3
4
5
6
7
8
9
for( ; )
//instructions
String[] t = {a”,b”,c”,d”,e”,f”,g”,h”,i”,j”,k”};输出:
for(字符串 s:t)
System.out.println(s);
a
b
c
d
e
f
g
h
i
j
k
while(expression)表达式的条件计算并返回一个布尔值。如果是 true,while 循环执行块并继续执行,直到表达式计算返回值 false.
//instructions
int nb=8;结果:
while(nb>0)
System.out.println(nb--);
8
7
6
5
4
3
2
1
do {
//bloc
}while(expression);
nb=1;输出:
do{
System.out.println(nb++);
}while(nb%10!=0);
1参考:
2
3
4
5
6
7
8
9
Please disable your ad blocker and refresh the window to use this website.