What is “While Loop”? Write its syntax?
OR
What is "For Loop"? Write its syntax?
Answers
Answer:
The while loop has the following syntax: while (condition) { // code // so-called "loop body" } While the condition is truthy, the code from the loop body is executed. For instance, the loop below outputs i while i < 3 : let i = 0; while (i < 3) { // shows 0, then 1, then 2 alert( i ); i++; }
Hope it's helpful
The while loop has the following syntax: while (condition) { // code // so-called "loop body" } While the condition is truthy, the code from the loop body is executed. For instance, the loop below outputs i while i < 3 : let i = 0; while (i < 3) { // shows 0, then 1, then 2 alert( i ); i++; }
The init step is executed first, and only once. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop. After the body of the 'for' loop executes, the flow of control jumps back up to the increment statement.
Statement 1 sets a variable before the loop starts (int i = 0). Statement 2 defines the condition for the loop to run (i must be less than 5). If the condition is true, the loop will start over again, if it is false, the loop will end.
Hope it's helpful to you all.
Thank you :)