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

Re: dangerous behavior of while in zsh 5.6 ?



hello Bart,

> >     while (( i-- ))
> >         print $i
> This is just a syntax error for me (or prints the PS2 prompt if
> interactive), so I'm not sure how you're getting it to do anything.

i have the same behavior when interactive but no syntax error otherwise.

instead:

    {   repeat 2 print $[i++]
        while (( i-- )) print $i
    } |sed 10 | xargs

    > 0 1 1 0

    {   repeat 2
            print $[i++]
        while (( i-- ))
            print $i
    } |sed 10q | xargs

    > 0 1 1 0 -1 -2 -3 -4 -5 -6

but thanks to your enlightening explainations, i understand what's going
on and now have a short, gorgeous way to write a forever loop.

    nat () {
        local -i x=${1-0}
        while print $[x++]
    }

thank you very much, Bart.

regards.
marc



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