[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: testing, counting, & arithmetic in general
>Date: Tue, 18 Jul 1995 16:11:46 -0400
>From: "Gregory L. Snead" <gsnead@harlequin.com>
> Is this how I'm expected to do this type of operation in es?
>
> i=1
> while {test $i -le 10} {
> echo $i
> i=`{expr $i + 1}
> }
>
>
> I.e. use "/bin/test" for conditionals (where ~ and ~~ aren't
>appropriate) and "/bin/expr" for arithmetic operations?
You might try something ~2 orders of magnitude faster for large loop counts:
for (i = `{bc <<< 'for (i = 1; i <= 1000; i++) i'\n}) \
{echo $i}
u=rittle@supra; time { i=1
while {test $i -le 1000}{
echo $i
i=`{expr $i + 1}
}
} >/dev/null
92r 18.7u 58.4s {...}
u=rittle@supra; time {for (i=`{bc <<<'for(i=1;i<=1000;i++)i'\n}){echo $i}} >/dev/null
1r 0.6u 0.7s {...}
--
Loren J. Rittle (rittle@comm.mot.com) Ripem-1.2 MD5OfPublicKey:
Systems Technology Research (IL02/2240) D2CE4A0F2BABF33AEF10C8C669DD782D
Motorola, Inc. PGP-2.6 Key fingerprint:
(708) 576-7794 6810D8AB3029874DD7065BC52067EAFD