晶文摘
(夏肇毅 製圖)
作者:夏肇毅 2010-12-17 初版
和For..Next 一樣
想重複指令做很多次
現在改一個方式
加一個判斷式
只要判斷式為真就重複執行
在 BASIC 中
以 "While 判斷式 ....WEnd 表示"
夾在中間的就是會重複執行的指令
BASIC:
' *******************************************
' while loop statement
' *******************************************
Sub WhileLoop()
Dim i as Integer
Debug.Print " ";"**** While statement ***";
Debug.Print
i=1
While (i<=5)
Debug.Print " ";"i=";
Debug.Print " ";i;
Debug.Print
i=i+1
WEnd
End Sub
C++:
/* ******************************************* */
/* while loop statement */
/* ******************************************* */
void WhileLoop() {
int i;
printf(" %s" , "**** While statement ***");
printf("\n" );
i=1;
while (i<=5) {
printf(" %s" , "i=");
printf(" %d" , i);
printf("\n" );
i=i+1;
}
}
JAVA:
// *******************************************
// while loop statement
// *******************************************
public void WhileLoop() {
int i;
System.out.print(" "+"**** While statement ***" );
System.out.println("");
i=1;
while (i<=5) {
System.out.print(" "+"i=" );
System.out.print(" "+i );
System.out.println("");
i=i+1;
}
}
C#:
/* ******************************************* */
/* while loop statement */
/* ******************************************* */
public void WhileLoop() {
int i;
Console.Write(" "+"**** While statement ***");
Console.WriteLine("");
i=1;
while (i<=5) {
Console.Write(" "+"i=");
Console.Write(" "+i);
Console.WriteLine("");
i=i+1;
}
}
PHP:
/* ******************************************* */
/* while loop statement */
/* ******************************************* */
function WhileLoop() {
echo " "."**** While statement ***";
echo "";
$i=1;
while ($i<=5) {
echo " "."i=";
echo " ".$i;
echo "";
$i=$i+1;
}
}