The document discusses JavaScript loops. It explains that the while loop loops through code while a condition is true and provides the syntax. An example prints numbers from 0 to 4 using a while loop. It also explains that the do...while loop is similar but executes the code block first before checking the condition, so it will run at least once even if the condition is false. Syntax and an example using a do...while loop are provided.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
24 views2 pages
15 While Loop
The document discusses JavaScript loops. It explains that the while loop loops through code while a condition is true and provides the syntax. An example prints numbers from 0 to 4 using a while loop. It also explains that the do...while loop is similar but executes the code block first before checking the condition, so it will run at least once even if the condition is false. Syntax and an example using a do...while loop are provided.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2
JavaScript While Loop
Loops execute a block of code a specified number of times, or while a specified
condition is true. The while Loop The while loop loops through a block of code while a specified condition is true. Syntax while (var<=endvalue) { code to be executed } Note: The ! could be any comparing statement. "xample The example below defines a loop that starts with i!#. The loop will continue to run as long as i is less than, or e$ual to %. i will increase by & each time the loop runs' "xample <html> <body> <script type="text/javascript"> var i=! while (i<=") { document#write("$he number is " % i)! document#write("<br />")! i%%! } </script> </body> </html> The do...while Loop The do...while loop is a variant of the while loop. This loop will execute the block of code ()*", and then it will repeat the loop as long as the specified condition is true. Syntax do { code to be executed } while (var<=endvalue)! "xample The example below uses a do...while loop. The do...while loop will always be executed at least once, even if the condition is false, because the statements are executed before the condition is tested' "xample <html> <body> <script type="text/javascript"> var i=! do { document#write("$he number is " % i)! document#write("<br />")! i%%! } while (i<=")! </script> </body> </html>