Perl last Statement - Tutorialspoint

文章推薦指數: 80 %
投票人數:10人

Perl last Statement, When a last statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next ... Home CodingGround Jobs Whiteboard Tools Business Teachwithus PerlBasics Perl-Home Perl-Introduction Perl-Environment Perl-SyntaxOverview Perl-DataTypes Perl-Variables Perl-Scalars Perl-Arrays Perl-Hashes Perl-IF...ELSE Perl-Loops Perl-Operators Perl-Date&Time Perl-Subroutines Perl-References Perl-Formats Perl-FileI/O Perl-Directories Perl-ErrorHandling Perl-SpecialVariables Perl-CodingStandard Perl-RegularExpressions Perl-SendingEmail PerlAdvanced Perl-SocketProgramming Perl-ObjectOriented Perl-DatabaseAccess Perl-CGIProgramming Perl-Packages&Modules Perl-ProcessManagement Perl-EmbeddedDocumentation Perl-FunctionsReferences PerlUsefulResources Perl-QuestionsandAnswers Perl-QuickGuide Perl-UsefulResources Perl-Discussion SelectedReading UPSCIASExamsNotes Developer'sBestPractices QuestionsandAnswers EffectiveResumeWriting HRInterviewQuestions ComputerGlossary WhoisWho PerllastStatement Advertisements PreviousPage NextPage  PerlOnlineTraining 46Lectures 4.5hours DeviKillada MoreDetail COMPLETEPERLProgramming 11Lectures 1.5hours HarshitSrivastava MoreDetail PerlforBeginners:LearnAtoZofPerlScriptingHands-on 30Lectures 6hours TELCOMAGlobal MoreDetail Whenalaststatementisencounteredinsidealoop,theloopisimmediatelyterminatedandtheprogramcontrolresumesatthenextstatementfollowingtheloop.YoucanprovideaLABELwithlaststatementwhereLABEListhelabelforaloop.AlaststatementcanbeusedinsideanestedloopwhereitwillbeapplicabletothenearestloopifaLABELisnotspecified. Ifthereisanycontinueblockontheloop,thenitisnotexecuted.Youwillseethecontinuestatementinaseparatechapter. Syntax ThesyntaxofalaststatementinPerlis− last[LABEL]; FlowDiagram Example1 LiveDemo #!/usr/local/bin/perl $a=10; while($a<20){ if($a==15){ #terminatetheloop. $a=$a+1; last; } print"valueofa:$a\n"; $a=$a+1; } Whentheabovecodeisexecuted,itproducesthefollowingresult− valueofa:10 valueofa:11 valueofa:12 valueofa:13 valueofa:14 Example2 Let'stakeoneexamplewherewearegoingtouseaLABELalongwithnextstatement− LiveDemo #!/usr/local/bin/perl $a=0; OUTER:while($a<4){ $b=0; print"valueofa:$a\n"; INNER:while($b<4){ if($a==2){ #terminateouterloop lastOUTER; } $b=$b+1; print"Valueofb:$b\n"; } print"\n"; $a=$a+1; } Whentheabovecodeisexecuted,itproducesthefollowingresult− valueofa:0 Valueofb:1 Valueofb:2 Valueofb:3 Valueofb:4 valueofa:1 Valueofb:1 Valueofb:2 Valueofb:3 Valueofb:4 valueofa:2 perl_loops.htm PreviousPage PrintPage NextPage  Advertisements



請為這篇文章評分?