while和do while迴圈語句

2021-09-21 17:42:26 字數 595 閱讀 5522

格式:

while(判斷條件語句)else

system.out.println("繼續猜!");

guess = sc.nextint();

} if(guess == num)

sc.close();

}}格式:

dowhile(判斷條件語句);

例項一猜字遊戲

public class dowhiledemo else

system.out.println("繼續猜!");

guess = sc.nextint();

}while(guess != num);

if(guess == num)

}}

break:可以使用在switch結構和迴圈結構中,用於跳出當前結構。

案例

public class test 

system.out.print(i);

} }}

public class test 

system.out.print(i);

} }}

While 迴圈和 do while 迴圈

示例1 輸出1 100 輸出1 100 int i 0 while i 100 示例2 死迴圈 死迴圈 while true 示例3 計算 1 加到 100 計算 1 加到 100 int m 0 int sum 0 while m 100 system.out.println sum 示例 計算 ...

while迴圈 do while和for迴圈總結

迴圈結構的特點 特徵 迴圈條件 迴圈操作 迴圈體 迴圈變數 什麼是while迴圈 while 迴圈條件 特點 先判斷,在執行。while迴圈使用 什麼是do while迴圈 do while 迴圈條件 符合條件,迴圈繼續 否則,迴圈退出。注意 while 後分號不可少 特點 先執行,在判斷。比較wh...

for迴圈,while迴圈,do while迴圈

for int i 0 i 5 i while true for 迴圈和while 迴圈滿足條件才能進入迴圈體,do while 迴圈先進行一次迴圈才去判斷迴圈條件是否成立,如果成立繼續進入迴圈體進行迴圈,否則退出迴圈。break return continue 的區別。如果break包含在巢狀迴圈...