Perl do while - Perl Tutorial
文章推薦指數: 80 %
The last statement exits the do...while loop immediately. It acts as the break statement in C/C++. ... In this tutorial, you've learned how to use the Perl do...
SkiptocontentHome»PerldowhileSummary:inthistutorial,you’lllearnaboutPerldowhileloopstatementthatexecutesacodeblockrepeatedlyaslongasaconditionistrue.IntroductiontoPerldo…whilestatementThePerldo...whileloopstatementexecutesacodeblockrepeatedlyaslongasatestconditionistrue.Bothwhileanddo...whilestatementsterminatetheloopifthetestconditionisfalse.Unlikethewhilestatementthatcheckstheconditionatthebeginningofeachiteration,thedo...whilestatementcheckstheconditionattheendofeachiteration.Thefollowingillustratesthesyntaxofthedo...whileloopstatement:do{
#codeblock
}while(condition);Codelanguage:Perl(perl)Becausedo...whileloopstatementcheckstheconditionattheendofeachiteration,thecodeblockinsidetheloopalwaysexecutesatleastonce.Also,doisnotaloopblock.Therefore,youneedtouseotherstatementstocontroltheloopincludingnext,lastandredostatements.Thefollowingflowchartillustratesthedo...whilestatement:Perldo…whileloopexampleInpractice,youusethedo...whileloopstatementwhenyouwanttheloopexecutesatleastonebeforetheconditionischecked.Atypicalexampleofthisisthecommand-lineprogramthatrequestsusersforinputuntilanexitcommandisprovided.Forexample:#!/usr/bin/perl
usewarnings;
usestrict;
my$command;
print("Enteracommand,byetoquit.\n");
do{
print(">");
#convertcommandtolowercase
chomp($command=
延伸文章資訊
- 1How to break out of a loop in Perl - Educative.io
The last keyword will allow us to break out of the current enclosing loop. ... If we specify LABE...
- 2Perl last Statement
The Perl last statement is used inside a loop to exit the loop immediately. The last statement is...
- 3How do I break out of a loop in Perl? - Stack Overflow
Bareword "break" not allowed while "strict subs" in use at ./final.pl line 154. Is there a workar...
- 4Perl last Statement - javatpoint
Using the Perl last statement alone, you can exits only innermost loop. If you want to exit a nes...
- 5Loop controls: next, last, continue, break - Perl Maven
In Perl there are 3 loop control keywords. The two commonly used are next and last and there is a...