Software development is as old as human history, it has given us many a religious belief system, used to control human brains, ultimately eliciting desired behavior in the attached human body.
All control structures can be reduced to a conditional jump (see Control Structures (German)).
The unconditional while loop (endless loop) with a break before the repetition can be used to simulate complex free form case / when structures that do not fit the if / elseif cascade nicely.
With a conventional while loop, initialization/continuation code:is somethimes duplicated (see listing 3.1).
1 2 3 4 | ch = get_char()
while ch != EOF:
print(ch)
ch = get_char()
|
listing 3.2 shows, how this duplication can be avoided.
1 2 3 4 5 | while True:
ch = get_char()
if ch == EOF:
break
print(ch)
|
Another common problem is found in shell scripts, when it is necessary to determine whether one or more files actually exist (see listing 3.3).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # clear first_readable #a0 :;
first_readable=
# while (for each _file in screenlog.?) is (do) #a0
for _file in screenlog.?;
do
# if (_file is **not** readable?) then (yes) #a0
test -r "${_file}" ||
break #a0
# endif #a0
# set first_readable = "${_file}" #a0 :;;
first_readable="${_file}"
break #a0
done #a0
# if (first_readable is empty?) then (yes) #a0
test -z "${first_readable}" && ...
# endif #a0
|
figure 3.1 shows the logic behind the file existence check.