The JavaScript while statement creates a loop that executes a block of code as long as the test condition evaluates to true. Its syntax is: do { // body of loop; } while (condition); Here, The body of the loop is executed at first. Again it will check the while condition after the value incremented. The following illustrates the syntax of the while statement. Examples might be simplified to improve reading and learning. This is repeated until the condition becomes false. The “while” loop. WHILE loop statement works similar to the Basic loop statement except the EXIT condition is at the very beginning of the loop . The while statement is used to write condition-controlled loop in Python. x=x+1 Wend The output will be Here key point of the while loop is that the loop might not ever run. The flow chart of while loop looks as follows − Syntax Flow Chart. If any number is divisible then divisibleCount value will be incremented by 1. while (condition), where the code snippet between ‘{‘ and ‘}’ will be executed once before reading the condition inside the ‘while’. The loop in this example uses a for loop to collect the car The while loop has the following syntax: while ( condition) { } While the condition is truthy, the code from the loop body is executed. Then the condition is evaluated. Loop through a block of code as long as a variable (i) is less than 5: The while statement creates a loop that is executed while a specified condition is A decrements of number is must in 'while' loop so that while condition may become false after some time otherwise program may go into infinite loop. Just like if…then statement, it checks whether the condition is true or false. The syntax for a while loop is: while (condition) { Statement } The syntax can almost be directly translated into English: do something while a condition is met . While...Wend loop is similar to Do While loop though not used commonly. If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: var cars = ["BMW", "Volvo", "Saab", "Ford"]; W3Schools is optimized for learning and training. while loop has one control condition, and executes as long the condition is true.