do-while和while的区别在于do-while最少会执行一次好吗。
先看do-while:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script language="Javascript" type="text/javascript" > var i=10; do{ i+=2 }while (i<10); alert(i); </script> </head> <body> </body> </html>
再看while:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script language="Javascript" type="text/javascript" > var i=10; while (i<10){ i+=2; } alert(i); </script> </head> <body> </body> </html>