On 15.10.2016 01:56, Hongyi Zhao wrote:
> Hi all,
>
> In the gawk manual page, I can find the descriptions on the control
> statements "do statement while (condition)".
>
> But, it's well known that gawk has the classical '/pattern/ {action}'
> construction. But, as you can see, in the 'do statement while
> (condition)' control statement, it basically is a '{action} /pattern/'
> construction.
I think you are here mixing up the awk'ish condition/action syntax with
the imperative statements that you find in awk's action part.
These two versions of awk's while-loops may appear _in the action part_
while (condition) statement
and
do statement ; while condition
(besides all the other imperative commands, like if, case, etc.).
>
> So, I just want to know why gawk designs this control statement like
> thins form instead of the form like 'while (condition) do statement'
> which is similar to the form used in the bash?
Programming language designers are free to define the supported forms
of conditional loops. One set of typical loops are classified by two
factors; whether the condition is checked on extry (i.e. before the
statement is exectuted), or checked on exit (after the first execution
of the statement), and in either positive or negated form. Informally
(keywords and syntax may differ depending on the language):
1. while cond do stmt
2. until cond do stmt
3. do stmt while cond
4. do stmt until cond
The shells (ksh, bash) support two forms, 1. and 2., awk and C supports
1. and 3., other languages support differnt forms, e.g. Pascal 1. and
4., Algol68 (in other design respects the prototype of shell design)
supports only 1., but the while loop in Algol is part of a much more
powerful loop construct (for ... while ... do ... od, with almost all
parts optional, depending on the desired semantics), and that you can
also find in Simula67 for example. Ignoring the more powerful Algol/
Simula loop you typically don't need all four loop variants since you
have usually the negation operator available that allows the designer
to support just 1. or 2. and 3. or 4. (The fact that shell supports 1.
and 2. results in more clumsy code to implement 3. or 4. which cannot
be simply emulated using the negation operator.)
Janis
>
> Regards
>