bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: documentation inconsistency


From: Neil R. Ormos
Subject: Re: documentation inconsistency
Date: Wed, 6 Oct 2021 00:50:43 -0500 (CDT)

J Naman wrote:

> # this is not a bug, it is a documentation inconsistency that perhaps
> # should remain 'undocumented' gawk 5.1.0 Win7 & 5.1.1f Ubuntu 20 something
> # 7.4.4 The for Statement: "The initialization, condition, and increment
> #       parts are arbitrary awk EXPRESSIONS, and body stands for any awk
> #       awk STATEMENT.
> #       The for STATEMENT starts by executing initialization.
> # ...   "It isn't possible to set more than one variable in the
> #       initialization part without using a multiple assignment statement
> #       such as 'x = y = 0' statement."
> #       <or calling a function that assigns global variable(s)>
> 
> BEGIN{
> for(init_globals(3) ; foo<6 ; incr_globals(2)){
> print "foo= " foo " global2= " global2 " doc= '" doc "'"
> }
> exit 1
> }
> # ------------------------
> function init_globals(value){ foo=value;  global2=foo+10; doc="Init";}
> # ------------------------
> function incr_globals(incr){   foo+=incr; global2=foo+10; doc="Increment";}
> # ------------------------
> # result:
> # foo= 3 global2= 13 doc= 'Init'
> # foo= 5 global2= 15 doc= 'Increment'

This works, also.  

  gawk 'BEGIN{ for ( (i=2)+(j=4)+(k=6)+(l=8); j<15; j++) print i, j, k, l }'

The "isn't possible to set more than one variable
in the initialization part" language overstates
the consequence of the requirement that the
initialization part, if populated, be an awk
expression, which is conventionally realized as an
assignment statement.

I never noticed before that the initialization
part can be empty.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]