01:198:170 Chapter Notes - Chapter 20, 22: Apollo 14, Dynamic Array, Natural Language
JavaScript Arrays and Loops
●JavaScript Rules for 'for Loops'
●The parts of the for loop including what is allowed and not allowed in each part
for (<initialization>; <continuation>; <next iteration>){
<statement list>
}
●Initialization, continuation, and next iteration are the control specifications
○They control the loop by using an iteration variable
■They are normal variables, must be declared but we typically declare them at
the start of the loop
○They are called iteration variables only while they are serving to control the loop
●The World-Famous Iteration
○Iteration variable
○Starting point
○Continuation test
○Step size
○Reference to the iteration variable
●Infinite Loop
○Ex: for (var j=0; j < 3; i=i+1){…}
■The variable being compared in the <continuation> test, j, is not the one
incremented in the <next iteration> operation (i)
●Be able to trace through a loop and be able to figure out the values of the variables during an
iteration
●Indexing and rules for Arrays
○Indexing
is the process of creating a sequence of names by associating a base name
("Apollo") with a number ("13")
■When a new name is needed, the next number in sequence is used ("Apollo 14")
■Each indexed item is called an element
of the base-named sequence
○Indexing is important in computing bc of its close link to iteration: iterations can be used
to refer to all elements of a name; that is, a notation like A[j] can, on successive
iterations over j, refer to a different element of A
○The index origin
is the point at which indexing begins
■Index origin of JS is 0
○Rules for Arrays
■Arrays are normal variables initialized by new Array(<number of elements>)
■<number of elements> in the declaration is just that-- the number of array
elements
■Array indexing begins at 0
■The number of elements in an array is its length
■The greatest index of an array is <number of elements> -1 bc of the 0 origin
●Array declaration, initialization, indexing, length
taupebee294 and 9 others unlocked
9
01:198:170 Full Course Notes
Verified Note
9 documents