JS Loops 1

JS Loops 1 - do loop • Syntax do some statements...

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

View Full Document Right Arrow Icon
CS 170:JS Loops Kristian Stout [email protected]
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
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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; } Example for (i=0;i<5;i=i+1) {…}...
View Full Document

Page1 / 5

JS Loops 1 - do loop • Syntax do some statements...

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

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