For
A loop statement in programming that performs predefined tasks while or until a predetermined condition is met. Below is an example of a for loop in Perl that prints "Computer Hope" five times.
for ($i = 1; $i < 6; $i++) {
print "Computer Hope\n";
}
In the above example, the for loop first sets the variable $i to a value of 1; each time it executes, the $i variable is increased by 1, while it's less than 6 "Computer Hope" is printed to the screen.
Tip: Like any loop when creating a for loop make sure it condition will always be met to help prevent an endless loop.
- See the MS-DOS for command and forfiles command pages for further information on these MS-DOS and Windows command line commands.
- Information about the Linux version can be found on our Linux for command page.
- How do I create my own computer program?
Also see: Do, Foreach, Loop, Programming definitions, While