1.continue,break,ruturn
The eg:1-100 and
$ (function () { $ ("#hello"). Click (function () { var iNum = 0; for (var i = 1; i < 101; i++) { + = i; } alert (iNum) ;});
The result is: 5050
Change to break to see the results
$ (function () { $ ("#hello"). Click (function () { var iNum = 0; for (var i = 1; i < 101; i++) { if (i = = 5) { break; } + = i; } alert (iNum); });
The result is: 10
Conclusion One: Break: Jump out of the entire loop body
How much is continue look at the results?
1$(function ()2 {3$ ("#hello"). Click (function ()4 {5 varINum = 0;6 for(vari = 1; I < 101; i++)7 {8 if(i = = 5)9 {Ten Continue; One } AINum + =i; - } - alert (iNum); the }); -});
The result is: 5045, (executed except 5)
Conclusion Two: Continue skips the current condition of the loop
There are two ways to use return:
First use: Change to return to see what the result is?
The result is: no result, return End method body, jump directly outside the method body, so cannot print
The second usage of return: A method that returns a value
1$(function ()2 {3$ ("#hello"). Click (function ()4 {5 varINum = 0;6 for(vari = 1; I < 101; i++)7 {8 if(i = = 5)9 {TenI=A (i); One } AINum + =i; - } - alert (iNum); the }); - //the second use of return is that a method returns a value - functionA (i) - { +i + = 5; - returni; + } A});
The result is: 5015
Process parsing:
Conclusion Three: Return two usages, the first end of the entire method body, and the second, a method that returns a value
JS Supplemental trivia point (Continue,break,ruturn)