Perl while Loop - Tutorialspoint
文章推薦指數: 80 %
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
延伸文章資訊
- 1Perl while Loop - Perl Tutorial
The Perl while loop statement executes a code block repeatedly as long as the test condition rema...
- 2Perl 學習手札- 9. 再談控制結構 - Easun.org
不過如果能夠小心使用,這些控制程式流程的工具會是程式設計師重要的工具。所以我們就來看看除了之前提過的for,while,until,if等等各式各樣的流程控制之外, ...
- 3控制結構(Control Structures) - Perl 程式設計 - 開源教學
Perl 沒有真正的真值(true value) 和偽值(false value),程式內部會自動判定值 ... my $n = 10; while ($n > 0) { print "Coun...
- 4while - Perldoc Browser
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please con...
- 5Perl | Loops (for, foreach, while, do...while, until, Nested loops)
A while loop generally takes an expression in parenthesis. If the expression is True then the cod...