JS Loops 1

# JS Loops 1 - } Example for (i=0;i<5;i=i+1) {} How to...

This preview shows pages 1–8. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
while loop Syntax: while (condition) { some statements; <increment;> } The code between { } gets executed for as long  as the condition is true and breaks out of the  loop when condition is false.
if versus while if (condition) } statements within { } get executed just once while (condition) {…} statements within { } get executed as long as  condition is true

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
do loop Syntax: do { some statements; increment; } while (condition); Statements within { } get executed at least once. The condition  decides whether the next iteration is to be performed or not.
for loop A for loop has three parts separated by semicolons. for (initialization; continuation; increment) { some statements;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } Example for (i=0;i<5;i=i+1) {} How to output variable document.write(text1+varname+text2); alert(text1+varname+text2); JS Sample Problem Write an algorithm for a program that will satisfy the following requirements: Asks a user how many numbers they want to calculate Compute the sum of the numbers from 1 to the number entered in the step above Prints out the sum Create a flowchart for the above algorithm Implement the above algorithm and flowchart using Javascript Exercise 1.Give JS code for (i=0;i<5;i=i+1) {} Whats the value of i after the loop? 2. Give JS code while (--i<=0) {} Whats the value of i after the loop?...
View Full Document

## This document was uploaded on 04/27/2011.

### Page1 / 8

JS Loops 1 - } Example for (i=0;i<5;i=i+1) {} How to...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online