Javascript ?? ???? ?? ?
???
for ??
for (?1;?2;?3)
???
}
? 1(?? ??)? ???? ?? ?????. ? 2? ??(?? ??) ?? ??? ?????. ? 3? ??(?? ??)? ??? ? ?????.
?? ?? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>循環(huán)語句 for 循環(huán)</title> </head> <script type="text/javascript"> sum= 0; for(var i=1;i<=10;i++){ sum = sum + i; } document.write(sum); </script> <body> </body> </html>
? ??? 1?? 10??? ?? ?????.
?? ???? ????. i? ? ??
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>循環(huán)語句 for 循環(huán)</title> </head> <script type="text/javascript"> for(var i=1;i<=10;i++){ document.write("第"+i+"天<br>"); } </script> <body> </body> </html>
??? ?? i? ?? 1?? 10?? ?????. ?? ???,
while ?? ?? ??? ???. >
while(condition){ ?? ?? ??; }?:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>循環(huán)語句 while 循環(huán)</title> </head> <script type="text/javascript"> var i=1; while(i<10){ document.write("php 中文網(wǎng)<br>"); i++; } </script> <body> </body> </html>??: ??? ??? ???? ???. ?? ?? ??? ???? ? i++? ?????. ??? ??? i++? ??? i=1? ?? ?? i<10? ????? ??? ?? ?????.??? ?????. ?? ?????while ??? ???? ? ?? ?? ??? ?????. 1-10? ?? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>循環(huán)語句 while 循環(huán)</title> </head> <script type="text/javascript"> var i = 1; var sum = 0; while(i<=10){ sum = sum + i; i++; } document.write(sum); </script> <body> </body> </html>? ????? ??? 1?? 10? ?? ???
??: while ??? ??? ?? ???? ????. ??? ???? ?? ?????.
? ??? ?? i? ???? 1???. ?? ??? ????? ??? ?????. ??? ?? ??? ???? ??? ?? ???? ??????. ??> ?? ??, ?? ???? ???? i++? ???? ?? ?? ???? ?? ??? ?????.do....while ??
do{
}while(??);?? ??? ???????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>循環(huán)語句 do....while 循環(huán)</title> </head> <script type="text/javascript"> var i = 11; do{ document.write(i+'次'); i++; }while(i<10); </script> <body> </body> </html>?? ??? ?? i? ?? ?? 11?? ?? ??? ???? 11? ??? ? i++? ???? ???. ?? i? ?? 12??, ??? ???? ???? ???? ???? ??????. ??:
do while ??? ???? ? ?? ??????.
???? do while? ???? 1?? 10??? ?? ????. ??? ??? ????:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>循環(huán)語句 do....while 循環(huán)</title> </head> <script type="text/javascript"> var sum = 0; var i = 1; do{ sum = sum + i ; i++; }while(i<=10) document.write(sum); </script> <body> </body> </html>
?? ? ??
break ?? ??? ???? ? ?????.
continue? ???? ??? ???? ? ?????. ??? switch??break ?? ??? ?? ????. ???? ???? ?? <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>break</title>
</head>
<script type="text/javascript">
for(var i=1;i<=10;i++){
if(i==5){
//break;
continue;
}
document.write(i+"<br>");
}
</script>
<body>
</body>
</html>
??? ???? break? ???? ??? ??? ? ????. ?. ???
break i? ??? 5? ??? ???? ?? ????? 4?? ?????.
continue i? 5? ??? ???? ?????. ??? ?? ?????. ?? ??? ?? 5? ?? ?? ?????. 2? ?? ???? ????