{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture16_JavaScript5

Lecture16_JavaScript5 - JavaScript Lecture 5 Loops Infinite...

Info iconThis preview shows pages 1–8. 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 Document Right 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 Document Right 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 Document Right 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
Nested Loop Example for(var i=1; i<6; i++) { for(var y=0; y<i; y++) { document.write("*"); } document.write("This is line " + i + "<br>"); }
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}