Perl last Statement - Tutorialspoint
文章推薦指數: 80 %
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
延伸文章資訊
- 1Perl last Statement - Tutorialspoint
Perl last Statement, When a last statement is encountered inside a loop, the loop is immediately ...
- 2Perl next Statement
The Perl next statement is used inside a loop to start the next iteration and skip all code below...
- 35.7 迴圈控制
Perl 常見的迴圈有while、for、foreach、until,在每一種迴圈中,可以視情況,使用以下三種算符,來控制迴圈。 last 一次只能跳出一層迴圈語法:last 用例: $i=0;...
- 4Loop controls: next, last, continue, break - Perl Maven
- 5Loop controls: next, last - Code Maven
Loop controls: next, last ; next - evaluate the loop condition and if it is true go to the next i...