Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: counting in "for" loops
- X-seq: zsh-users 1954
- From: Bruce Stephens <b.stephens@xxxxxxxxx>
- To: Sven Guckes <guckes@xxxxxxxxxxxxxxxxx>
- Subject: Re: counting in "for" loops
- Date: 02 Dec 1998 16:50:42 +0000
- Cc: ZShell Users List <zsh-users@xxxxxxxxxxxxxxx>
- In-reply-to: Sven Guckes's message of "Wed, 2 Dec 1998 17:00:32 +0100"
- References: <19981202170030.A2789@xxxxxxxxxxxxxxxxx>
- Sender: B.Stephens@xxxxxxxxx
Sven Guckes <guckes@xxxxxxxxxxxxxxxxx> writes:
> Again, I look at the manual and I cannot find
> how to do a simple count within a for loop.
>
> $ for count in ???; do
> > echo -n $count
> > done
> 1 2 3 4 5 6 7 8 9 10
This works for me (with zsh-3.1.4):
for ((count=1; count<=10; count++)); do
echo $count
done
> Why isn't this in the manual as an example? *sigh*
The manuals don't have many examples, currently. By all means
contribute things that you'd like to see in future versions, and this
example seems useful. Although something like:
for ((count=0; count<10; count++))
would be a more common sort of requirement.
Alternatively {1..10} will expand to a list containing the numbers, so
for count in {1..10}; do
...
might be sufficient for what you want. Doing the same for
{1..1000000} and things will take more memory than is optimal, though.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author