Perl Learning: 2.9. The while Control Structure
2010-07-21 17:21
363 查看
2.9. The while Control StructureLike most algorithmic programming languages, Perl has a number of looping structures.[] The while loop repeats a block of code as long as a condition is true: [ ] Every programmer eventually creates an infinite loop by accident. If your program keeps running and running, you can generally stop it in the same way you'd stop any other program on your system. Often, typing Ctrl-C will stop a runaway program; check with your system's documentation to be sure. $count = 0; while ($count < 10) { $count += 2; print "count is now $count/n"; # Gives values 2 4 6 8 10 } As always in Perl, the truth value here works like the truth value in the if test. Like the if control structure, the block curly braces are required. The conditional expression is evaluated before the first iteration, so the loop may be skipped completely if the condition is initially false. |
相关文章推荐
- Learning Perl: 3.6. The foreach Control Structure
- Perl Learning: 2.6. The if Control Structure
- Learning Perl: 10.4. The Naked Block Control Structure
- Tasker to stop Poweramp control for the headset while there is an incoming SMS - frozen
- Perl Learning - 2 (If(), While(), Chomp(), <STDIN>)
- The basic GridView control structure
- Learning Perl: 4.8. The use strict Pragma
- Learning Perl: 4.9. The return Operator
- 2.9 Customizing the UISegmentedControl
- Data structure of the experimental order of a: a row of fast row(learning quick sorting).
- Learning Perl: 10.1. The unless Control Structure
- StructLayoutAttribute- control the physical layout of the data fields of a class or structure.
- Learning Perl: 5.2. Input from the Diamond Operator
- Learning Perl: 10.2. The until Control Structure
- Learning Perl: 2.8. The chomp Operator
- vs2008 There was a failure while initializing the Microsoft Visual SourceSafe source control provider. You cannot use this provi
- There was a failure while initializing the Microsoft Visual SourceSafe source control provider. You cannot use this prov
- ASP.NET - The Button Control
- Why do a lot of #defines in the kernel use do { ... } while(0)?
- Machine Learning Trick of the Day (1): Replica Trick