Perl next Statement - Tutorialspoint
文章推薦指數: 80 %
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
延伸文章資訊
- 1Perl的基本語法
Perl也有和C語言的break和continue一樣的指令,Perl叫它做last 和next (較口語化)。 # last是跳出現在所在的迴圈,next則是跳過下面的指令直接執行下一次的迴圈。
- 2Perl continue 语句 - 菜鸟教程
Perl continue 块通常在条件语句再次判断前执行。 continue 语句可用在while 和foreach 循环中。 语法. while 循环中continue 语句语法格式如下所示...
- 3continue - Perldoc Browser
When there is no BLOCK, continue is a function that falls through the current when or default blo...
- 4Perl continue 語句 - W3big
Perl continue 塊通常在條件語句再次判斷前執行。 continue 語句可用在while 和foreach 循環中。 語法. while 循環中continue 語句語法格式如下所示...
- 5Perl next Statement
The Perl next statement is used inside a loop to start the next iteration and skip all code below...