6️⃣

4.6 Do While Loop

4.6 Do While Loop

Difference Between while and do/while

Whatever is inside the do while loop will run once even if the condition given is false. A while loop would not run the code at all if the condition is false.

Example

let total = 0; let i = 0; do { // the code will run even though i > 5 is not true total += i; i++; } while (i > 5);
 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.