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

Re: Problems with for loops



On Feb 2, 12:35pm, Allen Belk wrote:
> Subject: Problems with for loops
> 
> #!/bin/zsh
> ((i = 0))
> for (( i -eq 0; i -le 10; i++ )) do echo "$i\n" done
> 
> ./array_test.zsh: parse error near `(( i -eq 0' [3]

Although the other answers so far have been correct, they've missed one
crucial detail:  You're using zsh 3.0.something, and the "for ((...))"
syntax is a new feature introduced by zsh 3.1.3 (I think it was).  If
you were using 3.1.6, for example, the error message would be "bad
math expression" rather than "parse error."

The 3.1 series is a beta release, so think carefully before upgrading.

The equivalent of the above "for" loop in syntax that 3.0 does support:

((i = 0))
while ((i <= 10)) do echo "$i"; ((i++)); done



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