JS Loops 1

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

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
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.
Background image of page 2
if versus while if (condition) } statements within { } get executed just once while (condition) {…} statements within { } get executed as long as  condition is true 
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
for loop A for loop has three parts separated by semicolons. for (initialization; continuation; increment) { some statements;
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
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 Right Arrow Icon
Ask a homework question - tutors are online