O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required