From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext
Unlock this course with a free trial
Join today to access over 25,000 courses taught by industry experts.
Learn about while-loops and do-while loops in JavaScript - JavaScript Tutorial
From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext
Learn about while-loops and do-while loops in JavaScript
- The next control structures we're going to look at in JavaScript are the while and do while loops. Unlike the for loops we looked at previously, these loops are usually used when we don't know exactly how many iterations we need for our loop to complete. So let's look at the basic syntax of while and do while loops. The while loop is pretty simple. It's just while, followed by parentheses, with some condition under which the code inside the while loop should be executed. And JavaScript will continue to run the code inside the loop body over and over again until the condition inside the parentheses is false. And something to note too is that if the condition is false to begin with, the code inside the loop will never be executed. And the do while loop is pretty similar to the while loop, except the condition for repeating another iteration comes after the body of the loop. And that's the main difference between while and do while loops. The while loop checks the condition before…
Contents
-
-
-
-
-
(Locked)
Learning objectives1m 16s
-
Learn about equality in JavaScript5m 31s
-
(Locked)
Learn about if-statements in JavaScript4m 8s
-
(Locked)
Learn about for-loops in JavaScript4m 53s
-
(Locked)
Learn about while-loops and do-while loops in JavaScript1m 29s
-
(Locked)
Handle and throw errors in JavaScript2m 34s
-
(Locked)
Learn about switch-case blocks in JavaScript1m 53s
-
(Locked)
Learn about ternary operators in JavaScript1m 34s
-
(Locked)
Learn the difference between block-scoped and function-scoped variables4m 29s
-
(Locked)
-
-
-
-
-
-
-
-
-