Liste des Groupes | Revenir à cl c |
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:On 21.04.2025 23:21, Keith Thompson wrote:
[...]C-style for loops have been used successfully for decades, and have>
been adopted by other languages (including bash, which isn't
particularly C-like).
I have to disagree on that. First I'm positive that Bash adopted
the Ksh loops (but incompletely!), and not the "C" loops.
Bash has two kinds of for loops. From the bash manual:
for NAME [ [in WORDS ...] ; ] do COMMANDS; done
and
for (( EXPR1 ; EXPR2 ; EXPR3 )) [;] do COMMANDS ; done
I'm referring to the second form, as I'm sure you know.
I see that ksh has something very similar.
I have no idea which shell
added the second form earlier, but both are clearly derived from C,
directly or indirectly.
[...]
[...][...] But you can still do things that
you can't do with a simple counted for loop, for example printing
powers of 3:
for (( i = 1; i < 1000; i *= 3 )) ; do echo $i ; done
Les messages affichés proviennent d'usenet.