Home >Web Front-end >JS Tutorial >Javascript Basic Tutorial: While Statement_Basic Knowledge
The function of a loop statement is to repeatedly execute the same piece of code. Although it is divided into several different types, the principle is almost the same; as long as the given conditions are met, the statements contained in the loop body will continue to execute. Once the conditions are no longer Terminate when satisfied.
The while loop is a pre-test loop, which means that the conditional judgment of whether to terminate is before the code is executed. Therefore, the body of the loop may not be executed at all. Its syntax is as follows:
while(expression) statement
When expression is true, the program will continue to execute statement statements until expression is false.
Two cases
Click the button below to loop the code block as long as i is less than 5.