clovis21@hotmail.com wrote:
>
> Hello all, I'm just starting, but I've come unstuck already. I'm
> trying to write a for .. do begin line, but I can't seem to get it to
> work:
>
> for i=0, 31 do $
> for k=0, 31 do $
> for j=0, 255 DO BEGIN
> real_b(i, k, j)=b(i, k, 2*j)
> imag_b(i, k, j)=b(i, k, (2*j)+1)
> print, i, k, j
> endfor
>
> In desperation I've tried the following:
>
> for i=1, 100 do begin
> print, i
> endfor
>
> and all that happens is that I get 101 printed, then a syntax error on
> the 'n' of endfor. What have I done wrong?
>
> Martin
Martin -
Hang in there man! Since IDL is interpreted line-by-line as you
enter commands, you can't enter loop constructs like you tried,
because those kinds of statements need to be *compiled*. To enter
these commands at the IDL prompt:
IDL> .run
- for i=1,100 do begin
- print, i
- endfor
- end
and you will get what you expect. Or you can do it on one line:
IDL> for i=1,100 do print, i
If you enter your commands like these examples, or put them into
a properly written .pro file and compile them, your statements
will work just fine:
; test.pro
PRO test, real_b, imag_b, b
for i=0, 31 do $
for k=0, 31 do $
for j=0, 255 DO BEGIN
real_b(i, k, j)=b(i, k, 2*j)
imag_b(i, k, j)=b(i, k, (2*j)+1)
print, i, k, j
endfor
return
end
Hope this helps.
Dave
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|