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

Re: leading zeros in for/foreach loops



On Feb 15,  7:07pm, Andy Spiegl wrote:
}
} Can someone please explain this to me?  Does this for loop do
} something strange with the variable "i"?  How can I avoid that?

If the first assignment to an undeclared variable occurs in an
arithmetic context, the variable is given numeric type (integer or
float, depending on what has been assigned to it).  "for (( ... ))"
syntax is such a context.

You can avoid this implicit declaration by explicitly declaring the
variable before using it in any of your loops, e.g., "typeset i" or
"declare i" or "local i" or the appropriate synonym.  Or "unset i"
after the loop is finished.



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