In this paper, we analyze the usage of javacript using break inner layer to jump out of outer loop. Share to everyone for your reference. The specific analysis is as follows:
Unlike PHP, looping out of a break in JavaScript requires adding extra tags. Take "hundred money to buy hundred chickens" for example (search Zhang Chujian, hundred money to buy hundred chickens). If you need to work out all of them, this is the following code:
Copy Code code as follows:
<body>
<script type= "Text/javascript" >
for (var i = 1;i<=18;i++) {
for (Var j=1;j<=33;j++) {
var k = 100-i-J;
if ((i+j+k) ==100 && (5*i + 3*j +K/3) ==100) {
document.write ("Rooster" +i+ "only; Hen" +j+ "only; Chick" +k+ "only; <br/>");
}
}
}
</script>
</body>
If you only need one answer, the break jumps out of the loop when you calculate the first result:
Copy Code code as follows:
<body>
<script type= "Text/javascript" >
Baiji
for (var i = 1;i<=18;i++) {
for (Var j=1;j<=33;j++) {
var k = 100-i-J;
if ((i+j+k) ==100 && (5*i + 3*j +K/3) ==100) {
document.write ("Rooster" +i+ "only, hen" +j+ "only, Chick" +k+ "only; <br/>");
Break Baiji;
}
}
}
</script>
</body>
I hope this article will help you with your JavaScript programming.