ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[±Ð¾Ç] (±Ð¾Ç²Ä6½g)JavaScript °j°é±Ô­z while

[±Ð¾Ç] (±Ð¾Ç²Ä6½g)JavaScript °j°é±Ô­z while

while°j°é±Ô­z
·í§Ú­Ìª¾¹D°j°é¥²¶·°õ¦æªº¦¸¼Æ®É¡Afor°j°é±Ô­z´N¬O³Ì¦nªº°j°é±Ô­z¡A¦ý¬O­Y¤£ª¾¹D°j°é¥²¶·°õ¦æªº¦¸¼Æ©O¡A¨º§Ú­Ì´N¥i¥H¨Ï¥Îwhile°j°é±Ô­z¡A¨ä®æ¦¡¦p¤U¡G
  1. while  (±ø¥ó¦¡)  
  2.        {­n­«½Æ°õ¦æªº±Ô­z°Ï¶ô}
½Æ»s¥N½X
While°j°é±Ô­z¬O¥Ñ«O¯d¦rwhile¶}©l¡A¦b¨ä«á¬O¤@­Ó±ø¥ó¦¡¡A¦Ó³o­Ó±ø¥ó¦¡«h¬O¤@­Ó¥¬ªL­È¹Bºâ¦¡¡A¦pªG³o­Ó±ø¥ó¦¡¦¨¥ß¡]¥¬ªL­È¹Bºâµ²ªG¬°True¡^¡A¨º»ò¦b¡y{}¡z¸Ìªº±Ô­z¡]±Ô­z°Ï¶ô¡^´N·|°õ¦æ¦Üµ²§À¡AµM«á¦A§PÂ_±ø¥ó¦¡¡A·í³o­Ó±ø¥ó¦¡¤£¦A¦¨¥ß®É¡Awhile°j°é±Ô­z´N·|°±¤î°õ¦æ¡C²{¦b§Ú­Ì¨Ó¤ñ¸û¤@¤Ufor»Pwhile°j°é±Ô­z¡G­pºâ1¥[¦Ü10¡G
for¼gªk¡G
  1. Y=0;
  2. for (x=1 ; x<=10 ;  x++)
  3. {
  4. y=y+x;
  5. }
½Æ»s¥N½X
while¼gªk¡G
  1. X=1;
  2. Y=0;
  3. While (X <= 10)
  4. {
  5.       Y=Y+X;
  6.        X=X+1;
  7. }
½Æ»s¥N½X
¬Ý§¹³o¨â­Ó±Ô­zªº¤ñ¸û¡A±z¬O¤£¬Oµo²{¡G¦P¼Ëªº¥\¯à¡A¦ý¬Owhile°j°é±Ô­z¦ü¥G³Â·Ð¦h¤F¡A¤£¹L¡A­Y¤£ª¾¹D°j°é·|°õ¦æ´X¦¸¡AÁÙ¬Owhile°j°é±Ô­z¤ñ¸û¾A¦X¡A¦p¤U¨Ò¡G
¹ê°µ¾Ç²ß
½Ð³]­p¤@JavaScriptµ{¦¡¡A­pºâ6561¬O3ªº´X¦¸¤è¡A¨Ã±Nµª®×Åã¥Ü©óºô­¶¤¤¡C
  1. <BODY>
  2. 6561¬O3ªº¡G
  3. <Script LANGUAGE="JavaScript">
  4. test=6561;
  5. ans=0;
  6. while (test>1)
  7. {
  8. test=test/3;
  9. ans=ans+1;
  10. }
  11. document.write(ans+"¦¸¤è")
  12. </Script>
  13. </BODY>
½Æ»s¥N½X
¹ê°µ¾Ç²ß
½Ð³]­p¤@JavaScriptµ{¦¡¡A¦bºô­¶¤¤²£¥Í¤@4*5ªºªí®æ¡A¦p¤U¹Ï¡G
8.png
while°j°é¸Ñªk
  1. <SCRIPT Language="JavaScript">
  2. x=1;
  3. y=1 ;
  4. document.write("<table border=1>");
  5. while (x<5)
  6. {
  7. document.write("<tr>");
  8.   while (y<6)
  9.   {
  10.    document.write("<td>;(" + x + "," +y +")</td>");
  11.    y++;
  12.   }
  13. document.write("</tr>");
  14. x++;
  15. y=1;
  16. }
  17. document.write("</table>");
  18. </SCRIPT>
½Æ»s¥N½X
for°j°é¸Ñªk
  1. <SCRIPT Language="JavaScript">
  2. document.write("<table border=1>");
  3. for (x=1 ; x<5 ; x++)
  4. {
  5. document.write("<tr>");
  6.   for (y=1 ; y<6 ; y++)
  7.   {
  8.    document.write("<td>(" + x + "," +y +")</td>");
  9.   }
  10. document.write("</tr>");
  11. }
  12. document.write("</table>");
  13. </SCRIPT>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

        ÀR«ä¦Û¦b : §g¤l¬°¥Ø¼Ð¡A¤p¤H¬°¥Øªº¡C
ªð¦^¦Cªí ¤W¤@¥DÃD