• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

The while Loop

Another powerful loop in JavaScript is the while loop. When you want a loop that uses a loop index, you naturally think of a for loop. However, you also might want a loop that doesn’t use a loop index at all—you might want to loop only until a certain condition becomes false (such as when you haven’t yet found the data item for which you’re searching an array). That’s where the while loop comes in. This loop evaluates an expression, and if it is true, executes a set of statements—no loop index needed. The loop keeps repeating as long as the specified condition is true.

while (condition) { 
    statements 
} 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint