Javacript uses the break inner layer to jump out of the outer loop for analysis. javacriptbreak
This article analyzes the usage of javacrept to exit the outer loop using the break inner layer. Share it with you for your reference. The specific analysis is as follows:
Unlike php, the break exists cyclically in javascript, and additional labels need to be added. Take "buy chicken for yuan" as an example (search for Zhang qiujian and buy chicken for yuan ). If you need to calculate all, the following code is used:
Copy codeThe Code is as follows: <Head>
</Head>
<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; chicken" + k + "only; <br/> ");
}
}
}
</Script>
</Body>
</Html>
If you only need one answer, the break jumps out of the loop when the first result is calculated:
Copy codeThe Code is as follows: <Head>
</Head>
<Body>
<Script type = "text/javascript">
Tianji:
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, chicken" + k + "only; <br/> ");
Break Tianji;
}
}
}
</Script>
</Body>
</Html>
I hope this article will help you design javascript programs.