Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

while vs do while javascript

// while vs do...while loops

/* while loops: check condition first. If true, execute code. */
let i = 0; 
while (i < 5) {
  console.log(i); // 0 1 2 3 4
   i += 1;
}

/* do-while loops: execute code at least once even if condition is false. 
Then check condition. If true, continue executing code. */
let j = 6;
do {
  console.log(j); // 6
    j += 1;
} while (j < 5);
 
PREVIOUS NEXT
Tagged: #javascript
ADD COMMENT
Topic
Name
3+6 =