Perl while Loop - Tutorialspoint

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

Perl while Loop, A while loop statement in Perl programming language repeatedly executes a target statement as long as a given condition is true. 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 PerlwhileLoop Advertisements PreviousPage NextPage  PerlOnlineTraining 46Lectures 4.5hours DeviKillada MoreDetail COMPLETEPERLProgramming 11Lectures 1.5hours HarshitSrivastava MoreDetail PerlforBeginners:LearnAtoZofPerlScriptingHands-on 30Lectures 6hours TELCOMAGlobal MoreDetail AwhileloopstatementinPerlprogramminglanguagerepeatedlyexecutesatargetstatementaslongasagivenconditionistrue. Syntax ThesyntaxofawhileloopinPerlprogramminglanguageis− while(condition){ statement(s); } Herestatement(s)maybeasinglestatementorablockofstatements.Theconditionmaybeanyexpression.Theloopiterateswhiletheconditionistrue.Whentheconditionbecomesfalse,programcontrolpassestothelineimmediatelyfollowingtheloop. Thenumber0,thestrings'0'and"",theemptylist(),andundefareallfalseinabooleancontextandallothervaluesaretrue.Negationofatruevalueby!ornotreturnsaspecialfalsevalue. FlowDiagram Herethekeypointofthewhileloopisthattheloopmightnoteverrun.Whentheconditionistestedandtheresultisfalse,theloopbodywillbeskippedandthefirststatementafterthewhileloopwillbeexecuted. Example LiveDemo #!/usr/local/bin/perl $a=10; #whileloopexecution while($a<20){ printf"Valueofa:$a\n"; $a=$a+1; } Hereweareusingthecomparisonoperator



請為這篇文章評分?