Common loop statements in javascript are: whileloop do whileloop and forLoop . All three types of loop statements have their own advantages.
1. While loop Format As follows: ## while (condition){ Code that needs to be executed } document.write("Here is the input of 1-50 printed by while:"); var i = 1; while(i<=50){ document.write(i); i++; } 2. do while loop The format is as follows: do{ Loop body 2 }while(logical judgment 1); # "); var k = 1; do{ document.write( k); k++; }while(k<=50); 3. for loop The format is as follows: for (initialization (1); logical judgment (2); Assignment (3)){ Loop body (4) } Execution process Is: 1--->2--->4-->3 When does the for loop end: When the logical judgment is false (false), This terminates the cycle. Example: Print from 1 to 100; for(var i=1;i<=100;i++){ document.wirter(" "+i) } ##The difference between the three is demonstrated by a small case: do{ ##document.write("Will this be entered into the page?");}while(1==2); for(var i=1;i==2;i++){ document .write("Will for be entered into the page here?"); } while(i==2){ document.write("While will this be input to the page?"); } Proved by actual practice: the content in the do while statement will be output directly.
Summary: The difference between for loop while loop do while loop is that: do while will execute the loop body once regardless of whether the logical conditions are met, while while and for But it won't. Attached jquery each() loop-try it yourself
|
The above is the detailed content of Detailed explanation of basic usage examples of jquery's each loop. For more information, please follow other related articles on the PHP Chinese website!