while loop
The while loop has the same function as the for loop. The while loop repeatedly executes a piece of code until a certain condition is no longer met.
while statement structure:
while(判断条件) { 循环语句 }
Use a while loop to complete the action of taking balls from the box, one at a time, a total of 6 balls.
Do...while loop
The basic principle of do while structure and the while structure are Basically the same, but it guarantees that the body of the loop is executed at least once. Because it executes the code first, then judges the condition. If the condition is true, the loop continues.
do...while statement structure:
do { 循环语句 } while(判断条件)
Try to output 5 numbers.
Use the do...while statement to output 6 numbers.
Exit the loop break
In while, for, do...while, while loop Use the break statement to exit the current loop and directly execute the following code.
The format is as follows:
for(初始条件;判断条件;循环后条件值更新){ if(特殊情况) {break;} 循环代码 }
The test results are output. If the result is passed, continue to output the next score. If the result is failed, exit and subsequent scores will not be output.
Continue loop continue
Statement structure:
for(初始条件;判断条件;循环后条件值更新){ if(特殊情况){ continue; } 循环代码 }
In the above loop, when a special situation occurs, this loop will be skipped, and subsequent loops will not be affected.
Example: Output test scores. If the score is passed, continue to output the next score. If the score is failed, the score will not be output.
In a university programming elective class, we got a set of student data participating in the class, which are name, gender, age and grade. , Next, we need to use JavaScript knowledge to pick out the names of all the freshmen girls.
Student information is as follows:
('Little A', 'Female', 21, 'Freshman'), ('Little B', 'Male', 23, 'Journal' ),
('Little C','Male',24,'Senior'), ('Little D','Female',21,'Freshman'),
('Little E','Female',22,'Female'), ('Little F','Male',21,'Freshman'),
('Little G','Female ',22,'sophomore'), ('little H','female',20,'senior year'),
('little I','female',20,'freshman' ), ('小J','male',20,'junior year')
The above is the detailed content of Detailed explanation of javascript flow control statement while loop and do...while loop syntax examples. For more information, please follow other related articles on the PHP Chinese website!