JavaScript? while ??
while ??: ??? true? ?? ?? ?? ??? ????? ?????.
while(??? ??)
{
??? true?? ?? ?? ??? ?????.
}
while ?? ?? ??:
Before ??? ???? ??? ????? ???(??? ???? ??? ???? ??).
while? ??? true?? ?? ??? ??({ })? ?? ?????. ??? ???? ??? ?????.
?? ???? "?? ????" ?? ??? ???. ?, ? ??? ?? ?? ??? ? ????. ??? ?? "?? ??"? ?????.
??? ?? ???????:
1~10 ??? ?? ??? ?????.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var i = 1; while(i<=10){ document.write(i); i++ //變量更新,是為了避免出現(xiàn)“死循環(huán)” } </script> </head> <body> </body> </html>
???? ??? ???. ? ?? ?? ? ??? ?????.
?? ???
??? ??
?? ????
1~100 ??? ?? ?? ??
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //變量初始化 var i = 1; //條件判斷 while(i<=100){ //如果是奇數(shù),則輸出 if(!(i%2==0)){ document.write(i+" "); } //變量更新 i++; } </script> </head> <body> </body> </html>