From the course: Cert Prep LPIC-1 Exam 102 (Version 5.0)

Unlock the full course today

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

Iterate with while loops

Iterate with while loops - Linux Tutorial

From the course: Cert Prep LPIC-1 Exam 102 (Version 5.0)

Start my 1-month free trial

Iterate with while loops

- [Instructor] The for loop is designed to loop through a finite number of items and when it gets to the end, it exits. It is possible to have a condition inside the for loop that will break out of the loop even before it runs out of items. A better idea is to use a loop with a condition built in. For this we have the while loop and until loops. The only difference is that the while loop will iterate while a condition is true and the until loop will iterate until the condition is true. I usually use a while loop over the until loop. Let's take a look at the syntax of the while loop. The condition inside the single square brackets follows the same rules as an if conditional inside of single square brackets, which means you can match on wildcards, but not regular expressions. The simplest while loop we can make is the infinite loop by replacing the condition with the word true. This loop will keep iterating forever, unless…

Contents