For faster navigation, this Iframe is preloading the Wikiwand page for
While循环 .
在编程语言 中,While循环 (英语:while loop )是一种控制流程 的陈述 。利用一个返回结果为布尔 值(Boolean)的表达式作为循环条件,当这个表达式的返回值为“真”(true)时,则反复执行循环内的代码;若表达式的返回值为“假”(false),则结束执行循环内的代码,继续执行循环下面的代码。
因为While循环在区块内代码被执行之前,先检查陈述 是否成立,因此这种控制流程 通常被称为是一种前测试循环(pre-test loop)。相对而言Do While循环 ,是在循环区块执行结束之后,再去检查陈述 是否成立,被称为是后测试循环。
程序示例
while 循环
'這是一個用While迴圈的例子
dim counter as Integer
dim Tick as Integer
counter = 5
tick = 1
Print "Start"
while counter > 0
counter = counter - tick
'迴圈語句
Wend
Print "End"
unsigned int counter = 5 ;
unsigned long factorial = 1 ;
while ( counter > 0 )
{
factorial *= counter -- ; /*當滿足迴圈條件(本例為:counter > 0)時會反覆執行該條語句 */
}
printf ( "%lu" , factorial );
public static void main ( str args [] ){
while true {
System . out . println ( "Hello World!" ) //因為條件已經固定為常量true,所以就會不斷執行迴圈內的語句
}
int counter = 0 ;
while counter < 5 {
System . out . println ( "已經運行了" + counter + "次" ) //因為條件限定為counter不大於5,所以在counter不大於5的情況下會不斷重複迴圈中的内容
counter ++ ;
}
}
a = 0
while a <= 10 : #如果a沒有大於10就執行
a = a + 1
print ( a )
{{bottomLinkPreText}}
{{bottomLinkText}}
This page is based on a Wikipedia article written by
contributors (read /edit ).
Text is available under the
CC BY-SA 4.0 license; additional terms may apply.
Images, videos and audio are available under their respective licenses.
{{current.index+1}} of {{items.length}}
Thanks for reporting this video!
This browser is not supported by Wikiwand :( Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience. Please download and use one of the following browsers:
An extension you use may be preventing Wikiwand articles from loading properly.
If you're using HTTPS Everywhere or you're unable to access any article on Wikiwand, please consider switching to HTTPS (https ://www.wikiwand.com).
An extension you use may be preventing Wikiwand articles from loading properly.
If you are using an Ad-Blocker , it might have mistakenly blocked our content.
You will need to temporarily disable your Ad-blocker to view this page.
✕
This article was just edited, click to reload
Please click Add in the dialog above
Please click Allow in the top-left corner, then click Install Now in the dialog
Please click Open in the download dialog, then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list, then click Install
{{::$root.activation.text}}
Follow Us
Don't forget to rate us
Oh no, there's been an error
Please help us solve this error by emailing us at
support@wikiwand.com
Let us know what you've done that caused this error, what browser you're using, and whether you have any special extensions/add-ons installed.
Thank you!