[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FOR statement

Eli Beckerman wrote:
> I just tried running a FOR loop in the hopes
> of incrementing the variable "i" by steps of 0.25 as follows:
> radius=fltarr(1000)
> FOR i=0.0, 100.0, 0.25 DO BEGIN
>   radius(i)=i
> And what I end up with is an array that starts
> with the value 0.75 and is incremented by steps of 1.
> I'm following the convention of the FOR statement as
> presented in IDL's online help. What am I doing wrong?!

You are using I as both an array index and a loop variable. This is not
a good idea.

Try this instead:

nx = 1000    ; number of values required
dx = 0.25    ; step size
x1 = 0.0     ; start value

radius = lindgen(nx) * dx + x1

print, radius[0:5]

Bottom line: Don't use loops to create mesh vectors or arrays.