Professional Documents
Culture Documents
Lecture 4
Lecture 4
The for statement, or the for loop, is used when it is necessary to repeat
statement(s) in a script or function, and when it is known ahead of time how
many times the statements will be repeated. The statements that are
repeated are called the action of the loop.
The variable that is used to iterate through values is called a loop variable, or
an iterator variable. For example, the variable might iterate through the
integers 1 through 5 (e.g., 1, 2, 3, 4, and then 5).
Finding Sums and Products
A very common application of a for loop is to calculate sums and
products.
Sums and Products with Vectors