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

Re: syntactic triviality



On Sun, 21 Dec 2014 10:33:18 -0800
Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> This is completely unimportant, but if anyone is interested:
> 
>      while true && true; do echo true; done
> 
> I'm wondering if, strictly speaking, the 'do' needs to be necessary.  

Yes, it is.

The expression after "while" can be any shell construct of the form
described in the manual as a "list", not just one ending in ";".  Try
this:

  while false; false; true; do echo true; done

Prints "true" until you interrupt it.

  while true; false; do echo false; done

Doesn't print anything.

The SHORT_LOOPS option allows you a bit more flexibility, typically more
useful with "for" than "while", but I'd strongly recommend against it
while you're still learning the basic syntax.  Apart from anything else
the "do" is adding to the clarity about where the loop starts.  Shell
syntax is unclear enough without magnifying the problem.  Read the
manual for the things you can do with it.

pws



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