For

Updated: 04/26/2017 by Computer Hope

For may refer to any of the following:

1. 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 and while the $i variable is less than 6, "Computer Hope" is printed to the screen.

Tip

Like any loop, when creating a for loop make sure it contains an exit condition (e.g., counter) that prevents an endless loop.

2. For is also a Windows command line command, see the for command page for information.

3. Linux command, see the for command page for further information about this command.

Do, Foreach, Iteration, Loop, Programming terms, While