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

Re: shortloops for while?



"Richard Hartmann" wrote:
> Hi all,
> 
> I am using setopt shortloops, which allows me to do
> 
>   for i in *; echo $i
> 
> Along the same lines, I would want to be able to do
> 
>   while true; echo this is neat
> 
> 
> Is there any reason this is not possible? Is it an oversight? Could
> something like this be added at some point in the future?

It does appear the parser doesn't support any short looping syntax for
while.  It may be to do with the fact that in regular shell parsing any
set of statements can come between the "while" and the "do":

  while true; false; do echo never got here; done

This is the reason why "if" requires you to use trickery for short
"loops".

You can do

for ((;;)); echo this is not quite so neat

and if you were really desperate you could use a global alias for
the ((;;)).

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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