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 continue流控制
定义和用法. continue 实际上是一个流控制语句而不是函数。如果有一个continueBLOCK连接到一个BLOCK(通常是在while或foreach),它将始终被执行之前的条件再次进行...
- 2Perl continue 语句 - 简单教程
Perl 中的**continue** 语句用于停止执行从continue 语句的下一语句开始到循环体结束标识符之间的语句,返回到循环体的起始处开始执行下一次循环continue 语句可用 ...
- 3Perl的基本語法
Perl也有和C語言的break和continue一樣的指令,Perl叫它做last 和next (較口語化)。 # last是跳出現在所在的迴圈,next則是跳過下面的指令直接執行下一次的迴圈。
- 4Perl continue Statement - Tutorialspoint
Perl continue Statement, A continue BLOCK, is always executed just before the conditional is abou...
- 5Perl continue 語句 - W3big
Perl continue 塊通常在條件語句再次判斷前執行。 continue 語句可用在while 和foreach 循環中。 語法. while 循環中continue 語句語法格式如下所示...