Perl next Statement
文章推薦指數: 80 %
The Perl next statement is used inside a loop to start the next iteration and skip all code below it. In practice, you often use the next statement in ...
SkiptocontentHome»PerlnextStatementSummary:inthistutorial,youwilllearnhowtousethePerlnextstatementtocontroltheflowoftheloops.IntroductiontoPerlnextstatementThePerlnextstatementisusedinsidealooptostartthenextiterationandskipallcodebelowit.Inpractice,youoftenusethenextstatementinconjunctionwiththeifstatementtospecifyaconditiontostartthenextiteration.Typically,youusethenextstatementinthewhileandforloopstatement.Forexamples.Inawhileloopstatement:while(condition){
nextif(expression);
#codetoprocesstheselectedelement
}Codelanguage:Perl(perl)Inaforloopstatement:for(@array){
nextif(expression);
#codetoprocesstheselectedelement
}Codelanguage:Perl(perl)ThenextstatementislikethecontinuestatementinC.ThefollowingflowchartillustrateshowthePerlnextisusedinconjunctionwithanifstatementinsideawhileloop.PerlnextstatementexamplesYouoftenusethenextstatementinthefor,whileanduntilloopstatements.Forthedo…whileanddo…untilstatements,youneedtoplaceablockforthenextstatement.1)PerlnextwiththeforstatementexampleLet’stakealookatthefollowingexample:#!/usr/bin/perl
usewarnings;
usestrict;
my@haystack=(1,4,3,2,5,6,8,7,9);
#getanintegerintherange1-9fromcommandline
my$needle=0;
do{
print"Enteranumbertosearch(1-9):\n";
$needle=int(
延伸文章資訊
- 1Perl continue流控制
定义和用法. continue 实际上是一个流控制语句而不是函数。如果有一个continueBLOCK连接到一个BLOCK(通常是在while或foreach),它将始终被执行之前的条件再次进行...
- 2Perl next Statement - Tutorialspoint
The Perl next statement starts the next iteration of the loop. You can provide a LABEL with next ...
- 3Perl next Statement
The Perl next statement is used inside a loop to start the next iteration and skip all code below...
- 4Perl - difference between 'next' and 'continue'? - Stack Overflow
The continue keyword can be used after the block of a loop. The code in the continue block is exe...
- 5continue - Perldoc Browser
When there is no BLOCK, continue is a function that falls through the current when or default blo...