while
JavaScript1.0+, JScript1.0+, ECMAScript1.0+ NES2+, Nav2+, IE3+, Opera3+ Syntax
while(condition){ code; }
Description
The while conditional statement evaluates the condition passed and executes the code within the block until the condition is no longer met. This is often used to evaluate the value of variables, and then perform tasks as well as to iterate through lines in a file when implemented on the server-side.
Example
Listing 6.272 defines a number and then asks the user for a second number. The user is continually asked for the second number until a number lower than the defined number is entered.
Listing 6.272 Using the while Statement to Check the Value Passed in
<html> <head> <title>Using while</title> </head> <body> ... |
Get Pure JavaScript 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.