Java 循环结构
aide吧
全部回复
仅看楼主
level 8
Java中有三种主要的循环结构:
while 循环
do…while 循环
for 循环
2017年02月01日 03点02分 1
level 8
while 循环
while ( 布尔表达式 )
{
//循环内容
}
2017年02月01日 03点02分 3
level 8
public class Test
{
public static void main(String args[])
{
int x = 10;
while( x > 0 )
{
System.out.print("x -> " + x );
x--;
}
}
}
2017年02月01日 03点02分 4
level 8
do…while 循环
do {
//代码语句
} while ( 布尔表达式 );
public class Test
{
public static void main(String args[])
{
int x = 10;
do {
System.out.print("X -> " + x );
x--;
}while( x > 0 );
}
}
2017年02月01日 03点02分 5
level 8
for循环
for循环执行的次数是在执行前就确定的
for(初始化; 布尔表达式; 更新)
{
//代码语句
}
public class Test
{
public static void main(String args[])
{
for(int x = 0; x < 20; x++)
{
System.out.print("x -> " + x );
}
}
}
2017年02月01日 03点02分 6
level 8
Java 增强 for 循环
for(声明语句 : 表达式)
{
//代码句子
}
public class Test
{
public static void main(String args[])
{
int [] key = {10, 20, 30, 40, 50};
for(int x : key)
{
System.out.print( x );
System.out.print(",");
}
}
2017年02月01日 03点02分 7
level 8
break 关键字
2017年02月01日 03点02分 8
break 主要用在循环语句或者 switch 语句中,用来跳出整个语句块
2017年02月01日 03点02分
break 跳出最里层的循环,并且继续执行该循环下面的语句
2017年02月01日 03点02分
level 8
continue 关键字
2017年02月01日 03点02分 9
continue 适用于任何循环控制结构中。作用是让程序立刻跳转到下一次循环的迭代
2017年02月01日 03点02分
在 for 循环中,continue 语句使程序立即跳转到更新语句
2017年02月01日 03点02分
在 while 或者 do…while 循环中,程序立即跳转到布尔表达式的判断语句
2017年02月01日 03点02分
level 13
[滑稽][滑稽][滑稽][滑稽]
2017年02月01日 03点02分 10
11级大神[滑稽]
2017年02月01日 03点02分
1