Re: Beginner fails miserabley at first hurdle 0.05 0.05 [message #10925 is a reply to message #10898] |
Tue, 03 February 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Martin writes:
> 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?
There is nothing wrong with either of these code fragments.
The problem is probably that you are trying to type this code
at the IDL command line, and that is really hard to do with
multi-line code such as FOR loops.
Put this code into a text file. Add and extra END statement
at the bottom of everything else, save the file as "junk.pro"
(my favorite name), and then when you want to execute the code
type this:
IDL> .Run junk
It will all work as you expect it to. You have made what is
called a main-level IDL program. If you want to run the code
over again, you can type this:
IDL> .Go
If you get really desperate, you may want to have a look
at my IDL Programming Techniques book. This whole business
of writing programs is explained quite extensively. You can
learn more about the book on my web page.
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|