Changes

Jump to navigation Jump to search
259 bytes added ,  17:24, December 2, 2008
in C and Java
Line 4: Line 4:  
Fortran introduced the do loop, which BASIC made into the for loop. A counter is given an initial value. If it is below the maximum value, the loop's instructions are executed. Then the counter is set to the next value.  
 
Fortran introduced the do loop, which BASIC made into the for loop. A counter is given an initial value. If it is below the maximum value, the loop's instructions are executed. Then the counter is set to the next value.  
   −
This example prints out the first five integers:
+
This trivial example prints out the first five integers:
 
  FOR I = 1 TO 5
 
  FOR I = 1 TO 5
 
   PRINT I
 
   PRINT I
 
  NEXT I
 
  NEXT I
 +
 +
C, Java and the other "[[curly brace]]" languages put all the control code on the first line. They typically start counting at zero, which is the first element in most arrays:
 +
 +
for (int i = 0; i < 5; i++) {
 +
 +
  System.out.println( employee(i) );
 +
 +
}
       
[[Category:Computer Programming]]
 
[[Category:Computer Programming]]
Siteadmin, Check users, nsTeam1RO, nsTeam1RW, nsTeam1_talkRO, nsTeam1_talkRW, oversight, Administrators
30,650

edits

Navigation menu