Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: while loop grammar question




On 2024-12-07 22:42, Lawrence Velázquez wrote:
On Sat, Dec 7, 2024, at 9:48 PM, Ray Andrews wrote:
aa=1
# This escape test isn't captured:
while (( aa < 10 ))
{
     echo $aa
     let aa++
}
...
I don't know whether this behavior is intentional or not.
A comparable "if" command errors out:

	% cat /tmp/users-30115-4.zsh
	if ((1))
	{
		print true
	}
	% zsh -f /tmp/users-30115-4.zsh
	/tmp/users-30115-4.zsh:5: parse error near `\n'


Yikes, gotchas within gotchas.  I expect something so fundamental is pretty deeply coded so might have to be lived with.  Even given your explanations above, it seems strange that the 'while' loop loops -- it knows it's a loop but it doesn't understand it's own break condition.  So it is critical where the left brace is?  As usual I'm thinking in C here.  So what would be the hygienic form?  Stick with 'do/done' all the time?  I'd prefer it throw an error consistently rather than accept the 'for' form above, which I use all the time. At least I'd expect 'for' and 'while' to have exactly the same grammar.  Thanks Lawrence.









Messages sorted by: Reverse Date, Date, Thread, Author