Getting Started with JavaScript (iii)

Source: Internet
Author: User

Steps to perform the loop structure

1, declare the cyclic variable;
2, judge the cycle conditions;
3, the implementation of the circulation body operation;
4, update the loop variable;
The loop executes until the condition is not set and jumps out of the loop.

[While Loop]

The expression in the while loop (), the result of which can be of various types. But in the end it will be true and false, and the transformation rule is the IF structure;
①boolean:true is True, False is false;
②string: The empty string is false, and all non-empty strings are true;
③number:0 is false, all non-0 figures are true;
④null/undefined/nan: All is false;
⑤object: All is true;

Operation Result:

[Do-while cycle]while Cycle Features:judge first, then execute;Do-while Cycle Features:The Do-while cycle is executed at least once, even if the initial conditions are not established ;

Operation Result:

[For Loop] 1, for loop has 3 expressions:① declares the cyclic variable; ② determines the cyclic condition; ③ updates the cyclic variable;Three expressions, separated by; For loop three expressions can be omitted, but two, indispensable; 2, the execution characteristics of the FOR loop:first judge, then execute.; 3, for loop three expressions can be composed of multiple parts, the second part of a number of judging conditions and &&, | | Links, part 13th separated by commas;

Operation Result:

[loop control statement] 1, break:jump out of this layer loop and continue with the statement following the loop. If a loop has multiple layers of nesting, then break can only jump out of one layer. 2, Continue:Skip the remaining code in this loop and proceed to the next loop. ① for A For loop, the statement executed after continue is a loop variable UPDATE statement I++;② the statement executed after the while, Do-while Loop, and continue, is a cyclic condition judgment; Therefore, when you use both loops, you must place continue in i++ Used later. Otherwise, continue will skip i++ leading to a dead loop.

Operation Result:

[Rule of circular nesting]The outer loop controls the number of rows. The inner loop controls the number of elements in each row. [The graph problem does the idea]1, determines the graph altogether several lines, the row number namely is the outer loop the number of times; 2. Make sure there are several elements in each line. There are several elements that indicate that there are several inner loops; 3. Determine the number of each element, which is the number of cycles per inner layer; Tips: If the number of each element is not fixed. Then, find the number of each element, the relationship to the line number, the relationship expression, which is the maximum value of the inner loop. (loop variable starting from 0) The rectangular question:

Right triangle problems

Parallelogram problems

Number triangle problem:

Getting Started with JavaScript (iii)

Related Article

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.