Difference between revisions of "Loop"
Jump to navigation
Jump to search
(not much science here) |
(for loop) |
||
| Line 1: | Line 1: | ||
A '''loop''' in [[Computer Programming]] is a section of instructions which are repeated - either endlessly or until a certain expected state occurs. | A '''loop''' in [[Computer Programming]] is a section of instructions which are repeated - either endlessly or until a certain expected state occurs. | ||
| + | A common error made by novice programmers is to program an infinite loop, i.e., one that never ends despite the programmer's hopes. | ||
| + | |||
| + | 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: | ||
| + | FOR I = 1 TO 5 | ||
| + | PRINT I | ||
| + | NEXT I | ||
| + | |||
| − | |||
[[Category:Computer Programming]] | [[Category:Computer Programming]] | ||
Revision as of 17:19, December 2, 2008
A loop in Computer Programming is a section of instructions which are repeated - either endlessly or until a certain expected state occurs. A common error made by novice programmers is to program an infinite loop, i.e., one that never ends despite the programmer's hopes.
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:
FOR I = 1 TO 5 PRINT I NEXT I