Perl next Statement - Tutorialspoint

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

The Perl next statement starts the next iteration of the loop. You can provide a LABEL with next statement where LABEL is the label for a loop. 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 PerlnextStatement Advertisements PreviousPage NextPage  PerlOnlineTraining 46Lectures 4.5hours DeviKillada MoreDetail COMPLETEPERLProgramming 11Lectures 1.5hours HarshitSrivastava MoreDetail PerlforBeginners:LearnAtoZofPerlScriptingHands-on 30Lectures 6hours TELCOMAGlobal MoreDetail ThePerlnextstatementstartsthenextiterationoftheloop.YoucanprovideaLABELwithnextstatementwhereLABEListhelabelforaloop.AnextstatementcanbeusedinsideanestedloopwhereitwillbeapplicabletothenearestloopifaLABELisnotspecified. Ifthereisacontinueblockontheloop,itisalwaysexecutedjustbeforetheconditionisabouttobeevaluated.Youwillseethecontinuestatementinseparatechapter. Syntax ThesyntaxofanextstatementinPerlis− next[LABEL]; ALABELinsidethesquarebracesindicatesthatLABELisoptionalandifaLABELisnotspecified,thennextstatementwilljumpthecontroltothenextiterationofthenearestloop. FlowDiagram Example LiveDemo #!/usr/local/bin/perl $a=10; while($a<20){ if($a==15){ #skiptheiteration. $a=$a+1; next; } print"valueofa:$a\n"; $a=$a+1; } Whentheabovecodeisexecuted,itproducesthefollowingresult− valueofa:10 valueofa:11 valueofa:12 valueofa:13 valueofa:14 valueofa:16 valueofa:17 valueofa:18 valueofa:19 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){ $a=$a+1; #jumptoouterloop nextOUTER; } $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 valueofa:3 Valueofb:1 Valueofb:2 Valueofb:3 Valueofb:4 perl_loops.htm PreviousPage PrintPage NextPage  Advertisements



請為這篇文章評分?