From the course: Learning Bash Scripting

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Working with "while" and "until" loops

Working with "while" and "until" loops - Bash Tutorial

From the course: Learning Bash Scripting

Working with "while" and "until" loops

- [Instructor] Loops are control structures that run a specific piece of code over and over until the loop is caused to end. There's two kinds of loops that are dependent on conditions, called while loops and until loops. The while loop runs for the duration of time when its condition is true and stops when that condition becomes false. The until loop runs for the duration of time when its condition is false and stops when that condition becomes true. The difference is fairly subtle, but depending on what you want your script to do, one may be more suitable than the other. Both types of loops start with the appropriate keyword and the condition to use to determine whether the loop should keep running. That's followed by do and the code to loop through. And then the construct ends with done. Let's take a look at the while loop with a simple example that counts up to 10. I'll create an integer variable with a value of 0.…

Contents