From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding loops

Understanding loops - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Understanding loops

- [Voiceover] Generally speaking, a loop is a piece of code that is repeated. There's usually a condition that controls the duration of the loop. There are several types of loops available in Perl. This loop which tests its condition before running the code is called a while loop. A while loop looks like this in Perl. It first tests the condition, and then, if the condition is true, it executes the code. It then tests the condition again, and continues executing the code, over and over again, until the condition is false. Execution then continues with the code after the loop. The until loop works just like the while loop, but the condition is reversed. In this case, the loop is executed while the condition is false, and execution continues after the loop when the condition is true. If you need the code to run at least once, you may use a do loop. This works with either while or until conditions. In this case, the loop control condition is tested after the code runs. Perl also provides…

Contents