Javacript uses break inner layer to jump out of outer loop to analyze _javascript techniques

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.