# The Infinite Loop in Perl

PERLServer Side ProgrammingProgramming Scripts

A loop becomes an infinite loop if a condition never becomes false. The for loop is traditionally used for this purpose. Since none of the three expressions that form the loop are required, in Perl, you can make an endless loop by leaving the conditional expression empty.

#!/usr/local/bin/perl
for( ; ; ) {
printf "This loop will run forever.\n";
}

You can terminate the above infinite loop by pressing the Ctrl + C keys.

When the conditional expression is absent, it is assumed to be true. You may have an initialization and increment expression, but as a programmer more commonly use the for (;;) construct to signify an infinite loop.

Updated on 29-Nov-2019 06:06:58