Lect19ForLoopsArrays - Indexing We access an element using...

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

View Full Document Right Arrow Icon
Announcements Check class announcements daily You must implement programming projects by yourself 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 For Loop Iteration statement General form for (initialize; test; expression) statement basically equivalent to Initialize while (test) { statement expression } If more than one statement use { } Semicolons are required Beware of infinite loop if semicolon after ) Example: ForLoop.html Example: ForLoopVariations.html
Background image of page 2
3 Nested Loops You can combine if, while and do while statements in several ways You can have an several nested if statements You can have if statements within while statements You can have while statements within if Example : NestedLoops.html Example : MultiplicationTable.html
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 One-Dimensional Arrays Problem You need to keep track of the scores of students in a class Declaring and handling 50 variables is not an easy task Arrays come to the rescue Array Collection of values that can be treated as a unit or individually var a = new Array(4) You can visualize an array as a set of variables one after another
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
Background image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Indexing We access an element using [ ] First element associated with index 0 (e.g., a[0]) An element of an array can be of any type and an array can hold different types of elements The length property represents the length of the array (e.g., a.length) We can print the contents of an array by using alert Example: ArrayEx.html 5 Definition of One-Dimensional Arrays Via array literal comma separated list of elements within square brackets var a = [2, 3, 5]; var b = ; // empty array Specified in the Array constructor var c = new Array(); var e = new Array(4); // defines array of size 4 6 Handling ERRORS We can detect errors by using window.onerror Example: ErrorHandler.js, Error.html Lets introduce some errors in Error.html 7 What is Top-Down Design? Lets go over an example Video Store Software Bottom-Up Design Top-Down Design...
View Full Document

Page1 / 7

Lect19ForLoopsArrays - Indexing We access an element using...

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