JS Loops 1 - for loop A for loop has three parts separated...

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

View Full Document Right Arrow Icon
CS 170:JS Loops Kristian Stout stouty@rci.rutgers.edu
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
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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for loop A for loop has three parts separated by semicolons. for (initialization; continuation; increment) { some statements; } Example for (i=0;i<5;i=i+1) {} 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...
View Full Document

This note was uploaded on 02/08/2011 for the course COMP APPS 198 taught by Professor Stout during the Fall '10 term at Rutgers.

Page1 / 6

JS Loops 1 - for loop A for loop has three parts separated...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online