• 将第一页放在扫描仪上
• 按扫描按钮
• 将下一页放在扫描仪上

2.`while`循环

if-else 语句极大地扩展了我们的编程能力，使得编写在不同情况下执行不同操作的程序成为可能。但是还有一件事会让我们的程序更强大一个数量级——循环

Java 有 4 种循环：`while``for``for-each``do-while`我们现在将深入研究其中的第一个。

``````while (condition)
statement;``````
`while`带有单个语句的循环的表示法
``````while (condition)
{
block of statements
}``````
`while`带有语句块的循环的表示法

3.循环的例子

``````int n = 5;
while (n > 0)
{
System.out.println(n);
n--;
}``````

``````5
4
3
2
1
``````

``````int  n = 0;
while (n < 10)
{
System.out.println(n);
n++;
}``````

``````0
1
...
8
9
``````

``````Scanner console = new Scanner(System.in);
while(console.hasNextInt())
{
int x = console.nextInt();
} ``````

``````while (true)
System.out.println("C");``````

``````Scanner console = new Scanner(System.in);
boolean isExit = false;
while (!isExit)
{
String s = console.nextLine();
isExit = s.equals("exit");
}``````

4.循环内循环

``````while (condition for outer loop)
{
while (condition for inner loop)
{
block of statements
}
}``````
`while`在另一个循环内循环（带有语句块`while`

``````int  n = 0;
while (n < 4)
{
System.out.println("Mom");
n++;
}``````

``````Mom
Mom
Mom
Mom
``````

``````int n = 0;
while (n < 5)
{
System.out.print("A");
n++;
}``````

``AAAAA``

``````int n = 0;

while (n < 4)
{

int m = 0;

while (m < 5)
{
System.out.print("A");
m++;
}

System.out.println();

n++;

}
``````

``````ААААА
ААААА
ААААА
ААААА``````

5. 比较循环 Java 和 Pascal

``````i := 3;
While i >= 0 Do
Begin
WriteLn(i);
i := i - 1;
End;``````
``````int i = 3;
while (i >= 0)
{
System.out.println(i);
i--;
}``````
``````i := 0;
While i < 3 Do
Begin
WriteLn(i);
i := i + 1;
End;``````
``````int i = 0;
while (i < 3)
{
System.out.println(i);
i++;
}``````
``````IsExit := False;
While Not isExit Do
Begin
isExit :=  (s = 'exit');
End;``````
``````boolean isExit = false;
while (!isExit)
{
String s = console.nextLine();
isExit = s.equals("exit");
}``````
``````While True Do
WriteLn('C');``````
``````while (true)
System.out.println("C");``````
``````While True Do
Begin
``````while (true)