Iteration

Home Up Run First Loop 
This free JavaScript tutorial teaches scripting, electronics, and numeric-analysis simultaneously. It teaches pure JavaScript for scientific and technical calculations.  You should be able to program calculations using  only Notepad and Internet Explorer in one or two hours.

 

Run First Loop

 

 

Iteration and Higher mathematics

 

Iteration Definition

Mathematics. A computational procedure in which a cycle of operations is repeated, often to approximate the desired result more closely.

Computer Science.

  1. The process of repeating a set of instructions mamy times or until a specific result is achieved.
  2. A cycle of a set of instructions to be repeated: After ten iterations, the program exited the loop.

Mathematics Application:

Algebra - In algebra you learned to solve equations for X. Your teacher may have told you to check your answer by substituting that number into the equation.  If your answer resulted in a equality, you can be certain that your answer was correct.  With a computer you can skip solving the equation and simply search for the solution by testing every number in a finite set of numbers.  For example, if you knew that X was an Integer between -1000 and +1000 you would have to do 2000 iteration to find all the solution.  Programmers use looping to perform repetitive operations.

Calculus - We use calculus to calculate the area under a curve of continuous function of x.  We can approximate the area under a curve with a number of rectangles with height f(x) and width of delta x).  The smaller the value of delta x the greater the number rectangles required cover the bounded area.  One iteration or loop is required to calculate area of each rectangle.  

 

JavaScript Methods of Looping - Before doing any physics or electronics calculations let us consider some methods of looping.  

Warning: Infinite Loops can hang up your computer.  Pressing Ctrl/Alt/Delete buttons simultaneously will interrupt program operation and cause Windows Task Manager Menu to be displayed.  Use  Windows Task Manager  -  End Task button to stop your program.

For Keyword

The for loop uses an index counter to keep track of the number loops, and stops looping when a certain number is reached.


<HTML>

<head>
<TITLE>Simple Script 1</TITLE>
</head>
<Body>
<SCRIPT LANGUAGE = JavaScript>
n = 10
for (i = 1; i < 8; i++){
n = n *n; 
alert("n = "+n)
}
alert("The End")
</SCRIPT>
</Body>
</HTML>

Notes:
i = 1 is start count.
 i < 8 defines upper limit
i++ means i = i + 1 or simply increment i.

Statements in parenthesis ( ) control loop.
Statements in wiggly parenthesis {} are operations to be performed in each loop. 

 

 

 

 

 

        
Questions or problems regarding this web site should be directed to BilPat4342@AOL.com

Copyright ©2003 Science Ebooks All rights reserved.
Last modified: Wednesday December 06, 2006.