Horje
perl exit loop Code Example
perl exit loop
# Basic syntax:
last;
# Where last is analogous to break in Python, Bash, R, etc

# Example usage:
for my $i (0 .. 5) {
	print "index is $i\n";
    # Exit the for loop if the index equals 3
	if ($i == 3) {
		last;
    }
}
perl exit loop example
my $counter = 1;
foreach $foo (sort {$importHash{$b} <=> $importHash{$a}} (keys %importHash))
{
  # push the string $foo onto the @tags array
  push @tags, $foo;
  
  # break out of our perl loop when the counter reaches 10
  last if ($counter++ == 10);
}




14

Related
perl post condition Code Example perl post condition Code Example
perl input output Code Example perl input output Code Example
perl foreach loop Code Example perl foreach loop Code Example
perl print an array Code Example perl print an array Code Example
perl math operators Code Example perl math operators Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12