2023-07-05 11:43:35 +02:00
|
|
|
# The while-loop
|
|
|
|
|
|
|
|
## Synopsis
|
|
|
|
|
|
|
|
while <LIST1> ; do
|
|
|
|
<LIST2>
|
|
|
|
done
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
The while-loop is relatively simple in what it does: it executes the
|
2024-01-29 02:07:56 +01:00
|
|
|
[command list](../../syntax/basicgrammar.md#lists) `<LIST1>` and if the exit
|
2023-07-05 11:43:35 +02:00
|
|
|
code of it was 0 (TRUE) it executes `<LIST2>`. This happens again and
|
|
|
|
again until `<LIST1>` returns FALSE.
|
|
|
|
|
|
|
|
This is exactly the opposite of the [until
|
2024-01-29 02:07:56 +01:00
|
|
|
loop](../../syntax/ccmd/until_loop.md).
|
2023-07-05 11:43:35 +02:00
|
|
|
|
|
|
|
:!: Like all loops (both `for`-loops, `while` and `until`), this loop
|
|
|
|
can be
|
|
|
|
|
|
|
|
- terminated (broken) by the `break` command, optionally as `break N`
|
|
|
|
to break `N` levels of nested loops
|
|
|
|
- forced to immediately do the next iteration using the `continue`
|
|
|
|
command, optionally as `continue N` analog to `break N`
|
|
|
|
|
|
|
|
### Return status
|
|
|
|
|
|
|
|
The return status is the one of the last command executed in `<LIST2>`,
|
|
|
|
or `0` (`TRUE`) if none was executed.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
## Portability considerations
|
|
|
|
|
|
|
|
## See also
|
|
|
|
|
2024-01-29 02:07:56 +01:00
|
|
|
- Internal: [The until loop](../../syntax/ccmd/until_loop.md)
|
2023-07-05 11:43:35 +02:00
|
|
|
- Internal: [code examples of the read builtin
|
2024-01-29 02:07:56 +01:00
|
|
|
command](../../commands/builtin/read.md#code_examples) to see how you can
|
2023-07-05 11:43:35 +02:00
|
|
|
loop over lines
|