關閉→
當前位置:知科普>IT科技>dowhile - java

dowhile - java

知科普 人氣:1.81W

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java dowhile是什麼,讓我們一起了解一下:

dowhile是一個循環,用於多次迭代程序的一部分或重複多次執行一個代碼塊。dowhile先執行循環體,再判斷條件,條件滿足,再繼續執行循環體,無論條件是否滿足,循環體至少執行一次。

dowhile的語法是什麼?

do {undefinedstatement(s)} while (expression);

布爾表達式在循環體的後面,所以語句塊在檢測布爾表達式之前已經執行了。如果布爾表達式的值為 true,則語句塊一直執行,直到布爾表達式的值為 false。

java dowhile

那麼dowhile與while有哪些區別?

dowhile 和 while循環有相似之處,但使用方法完全不同,一個是直到型循環,另一個是當型循環。區別在於表達式的值是在每次循環結束時檢查而不是開始時。和正規的 while 循環主要的區別是 do-while 的循環語句保證會執行一次(表達式的真值在每次循環結束後檢查),然而在正規的 while 循環中就不一定了(表達式真值在循環開始時檢查,如果一開始就為 FALSE 則整個循環立即終止)。

實戰操作:

public class Test {undefinedpublic static void main(String[] args) {undefinedint x = 10;do {undefinedSystem.out.print("value of x : " + x);x++;System.out.print("");} while (x < 20);}}

TAG標籤:#java #dowhile #