June 2014
Intermediate to advanced
696 pages
38h 52m
English
Another type of while loop is the do/while loop. This is useful if you always want to execute the code in the loop at least once and the expression cannot be tested until the code has executed at least once.
For example, the following do/while loop executes until the days is equal to Wednesday:
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];var i=0;do{ var day=days[i++]; console.log("It's " + day);} while (day != "Wednesday");
This is the output at the console:
It's MondayIt's TuesdayIt's Wednesday
Read now
Unlock full access