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

Re: while loop grammar question






On 2024-12-08 12:59, Lawrence Velázquez wrote:
It does understand its own break condition.  The issue is that the
break condition -- e.g., the command whose exit status matters --
is not where you think it is.
Right, that was clear from your previous examples.  Still there is an expectation that the break condition will be where you expect it to be and it ain't.  But as you say, this isn't something that's going to catch people very often.  I must say tho that your diagnostics are a deep dive into understanding this sort of thing -- nice to be able to look under the hood.

With an
arithmetic "for" loop, the ((...)) construct is actually part of
the syntax, so there's no confusion about where the loop body begins.
Ah!  So symmetry is not to be expected.  That changes my perspective.  It looks like the while loop is not just a more 'primitive' for loop, but has it's own unique bag of tricks.  That's a quite satisfying answer -- I've tended to think of the for loop as an 'upgraded' while loop.  Thank you Sensei. 


    
As usual I'm thinking in C here.
An understandable impulse but one that does not serve you well when
thinking about shell scripting grammar.

So devilishly difficult to get over one's mother tongue!  The habits get bolted onto your mind.  I still declare all my variables.  





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