Perl Programming for Beginners: An Introduction to Learn Perl Programming with Tutorials and Hands-On Examples by Metzler Nathan

Perl Programming for Beginners: An Introduction to Learn Perl Programming with Tutorials and Hands-On Examples by Metzler Nathan

Author:Metzler, Nathan [Metzler, Nathan]
Language: eng
Format: epub, pdf
Published: 2020-05-29T16:00:00+00:00


10.6.2 last Statement

The last statement is used to terminate the loop. When this statement is encountered, the execution control will come out of the loop. Here is a Perl script that demonstrated the usage of last statement . There is a loop which counts from 0 to 9 but when the count reaches 5, we break out of the loop using last statement .

#Control Statements Demo - last

#Run for loop from 0 to 9

$count = 0 ;

while ( $count < 9 )

{

​ #Check if count is 5

​ if ( $count == 5 )

​ {

​ #Come out of the loop

​ last ;

​ }

​ #Print count

​ print ( "\n $count " );

​ #Increment count

​ $count ++;

}

print ( "\n" );

Output:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.