关于java中的循环语句

来源:百度知道 编辑:UC知道 时间:2024/05/17 16:06:30
程序如下:
// Using break with nested loops.
class BreakLoop3 {
public static void main(String args[]) {
for(int i=0; i<3; i++) {
System.out.print("Pass " + i + ": ");
for(int j=0; j<100; j++) {
if(j == 10) break; // terminate loop if j is 10
System.out.print(j + " ");
}
System.out.println();
}
System.out.println("Loops complete.");
}
}
问题1:for语巨如果是for(){代码块}格式的,是不是说每次循环都执行一次代码块?
问题2:以上代码中,System.out.println();是什么意思?println()是把括号里的东西打出来,里面如果想上面的程序没东西是表示什么意思?

是的。每次循环语句块都要进行一次编译,这就是循环语句的特点。
System.out.println();括号内无参数是换行的意思,这一行不打任何字。

public class BreakLoop3 {

public static void main(String args[])
{
for(int i=0; i<3; i++)
{
System.out.print("Pass " + i + ": ");
for(int j=0; j<100; j++)
{
if(j == 10) break; // terminate loop if j is 10
System.out.print(j + " ");
}
System.out.println();
}
System.out.println("Loops complete.");
}

}
Pass 0: 0 1 2 3 4 5 6 7 8 9
Pass 1: 0 1 2 3 4 5 6 7 8 9
Pass 2: 0 1 2 3 4 5 6 7 8 9
Loops complete.
System.out.println()是换行的意思,写代码要形成格式化的好习惯,维护起来也好方便的.