w3pop.com :: ÍøÂçѧԺ :: JavaScript :: JS Break Ñ»·
There are two special statements that can be used inside loops: break and continue.
breakºÍcontinueÊÇÁ½¸öÓÃÔÚÄÚ²¿Ñ»·µÄÌØÊâÓï¾ä¡£
Break statement
Use the break statement to break the loop.
ʹÓÃbreakÓï¾äÌø³öÑ»·
Continue statement
Use the continue statement to break the current loop and continue with the next value.
ÓÃcontinueÓï¾äÀ´Ìø³öµ±Ç°µÄÑ»·¼ÌÐøÏÂÃæµÄÖµ
There are two special statements that can be used inside loops: break and continue.
breakºÍcontinueÊÇÁ½¸öÓÃÔÚÄÚ²¿Ñ»·µÄÌØÊâÓï¾ä¡££¨ºÍµÚÒ»¾äÖØ¸´ÁË-_-£©
The break command will break the loop and continue executing the code that follows after the loop (if any).
breakÃüÁî»áÀ뿪µ±Ç°µÄÑ»·²¢½Ó×Å¿ªÊ¼Ö´ÐÐÏÂÃæµÄÑ»·£¨Èç¹ûÓеϰ£©
Example
Àý×Ó
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3){break}
document.write("The number is " + i)
document.write("<br />")
}
</script>
</body>
</html>
|
Result
½á¹û
The number is 0 The number is 1 The number is 2 |
The continue command will break the current loop and continue with the next value.
continueÃüÁî»áÌø³öµ±Ç°µÄÑ»·²¢¼ÌÐøÏÂÃæµÄÖµ
Example
Àý×Ó
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3){continue}
document.write("The number is " + i)
document.write("<br />")
}
</script>
</body>
</html>
|
Result
½á¹û
The number is 0 The number is 1 The number is 2 The number is 4 The number is 5 The number is 6 The number is 7 The number is 8 The number is 9 The number is 10 |
ÆÀÂÛ (0)
All