While

Updated: 06/30/2020 by Computer Hope

While may refer to any of the following:

while loop

1. A while loop or repeat loop is a loop statement in programming that performs a pre-defined task repeatedly until a condition is met. For example, in the Perl code below, a while loop opens the file "file.txt." While going through each of the lines in the file, the code prints them if they contain any lowercase or uppercase letters.

open (INPUT, "<file.txt");
while (<INPUT>) {
 if ($_ =~ /[a-zA-Z]/) {
  print "$_";
 }
}
close (INPUT);
Tip

Like any loop, when creating a for loop make sure it contains a condition to exit the loop and prevent an endless loop.

2. While is also a Linux command, see the while command page for further information about this command.

Do, Iteration, Loop, Programming terms