Today #day29 of #100daysofcode, I have completed 3.19,3.20 lessons and a practice program in JS. @Sololearn
The while loop
- As long as the condition is true the while loop repeats the block of code.
- syntax:
while (condition) { code block}
- the condition can be any conditional statement which returns true or false.
Note:
- while writing condition be careful with the conditional statement if it is true always then the loop will run forever.
- make sure the conditional statement of a condition in while loop becomes false eventually.
The do... while loop
- do while loop is a variant of the while loop but the main difference is 'the while loop' checks the condition before executing a block of code whereas 'the do... while loop' executes code of block and then checks condition and then it repeats until the conditional statement eventually becomes false.
- syntax:
do {code block} while (condition);
Images:
Conclusion
- The while loop
- The do... while loop
- code
- quiz