The interpreter evaluates the condition every time the before the while loop is executed, if false then the control moves to the statement right after the closing curly braces .
Syntax: while loop
The structure of do/while loop is fundamentally different than while loop.
In do/while loop the condition is evaluated after executing the code, while its opposite with while loop.
A standard for statement consists of three clauses in parentheses:
The first clause initializes the expression.
The second clause sets the test condition for the loop to be executed.
The third clause is used to increment the counter of the loop
It enables the user to loop through each element in the array with having to know the number of element the array actually contains
Rather than working with index number of each element, it automatically moves to the next index with each iteration.
The break statement is used to exit the loop immediately, and thus forcing execution to continue with the statements after the loop.
The continue statement is used to exit the loop immediately, but unlike the break statement, the execution continues from the top the loop.
In the below demo, the loop executes for a total of 8 times, it exits once at i = 5, and then begins executing from the top of the loop and executes a total of 8 times and not 9 as one increment does not happen after i = 5.
Labels are optional, and are used to control the flow of loops.The label name should not be a reserved word
Nested Loops : Nested loops are created by having one loop within the another,it is most commonly used to display data in a matrix(rows and columns).
The outer loop is first initialized and tested , the inside loop then iterates through all its cycles, the process is repeated till the outer loop condition is false.