Lecture16_JavaScript5

Lecture16_JavaScript5 - JavaScript: Lecture 5 Loops...

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

View Full Document Right Arrow Icon
JavaScript: Lecture 5 Loops Infinite Loops Nested Loops Interchangeability in loops Two ways to end a loop More loop Examples
Background image of page 1

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

View Full DocumentRight Arrow Icon
Infinite loops An infinite while loop while (true) { document.write (“Hello<br>”); }
Background image of page 2
Infinite loops An infinite DO loop var i=1; do { document.write("Lather"); document.write("Rinse"); document.write("Repeat"); } while (i<=2);
Background image of page 3

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

View Full DocumentRight Arrow Icon
Infinite loops An infinite for loop: for (i=0;i<10;i--) { document.write ("This is line " + i); }
Background image of page 4
Nested Loops A loop within a loop Steps: The outside loop is initialized and tested (starts) Then the inner loop starts, and iterates completely through all of its cycles Then the outside loop continues
Background image of page 5

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

View Full DocumentRight Arrow Icon
Nested Loops Any loop type (for, do or while) can be nested inside any loop type Any number of loops can be embedded Each time you enter a loop from the top (new entry), the loop counter re-initializes Each time you enter a loop from the bottom (repeating), the loop counter continues to increment
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

Lecture16_JavaScript5 - JavaScript: Lecture 5 Loops...

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

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