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

Re: shortloops for while?



On Tue, Jun 17, 2008 at 03:42:12PM +0200, 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?
[...]

The normal syntax for while is:

while list1-of-comands
do list1-of-commands
done

So you have to have a way to tell while where the first list of
commands end.

You can use the short version only when list1-of-commands is
((...)) or [[...]] and list2-of-commands is bound by {} or ().

while ((1)) {echo this is neat}



while true; echo this is neat

would be parsed as while and the first two commands of
list1-of-commands.

It's true that zsh could probably have been made to allow:

while { list1 } { list2 }

There might be good reasons why it's not supported though.

-- 
Stéphane



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