Using a While Loop

var weekdays = ["Mon", "Tue", "Wed", "Thur", "Fri"]; do{   document.write(day);   var day = weekdays.pop();   document.write(day+", "); } while (day != "Wed"); //Output is "Fri, Thur, Wed, "

The while(condition){LOOP_BLOCK} and do{LOOP_BLOCK}while(condition); loops allow you to loop through code until a specific condition occurs. The code in your LOOP_BLOCK is executed each time through the loop.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.