comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Stupid Question#1
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Stupid Question#1 [message #13310 is a reply to message #13308] Mon, 02 November 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
rob cosgrave (r.cosgrave@ucc.ie) writes:

> am having a spot of bother with smething that should be really
> simple. I cannot get FOR ....DO BEGIN ENDFOR loops to work. I thought
> first it was something to do with my program, so I tried a really simple
> one, and that didn't work. Then I cut and paste the example out of the
> online documentation and that didn't work. And then I tried running one
> of the scripts which came with IDL and that didn't work either. They
> all failed at the endfor, and didn't close the loop.
> I thought it was just me doing something stupid, but when
> the programs that came with it failed also...
> My version is the IDL student on a Win95 machine. Could the
> student editionness be the problem?
> Again, apologies for the dumb question, but this is driving me crazy,
> and it's kinda hard to program without loops!

I'm guessing that you are trying to run these FOR loops
at the IDL command line and that is what is causing
you the problems. A FOR loop is a single command to the
IDL interpreter, so you must enter it as a single command
at the IDL command line. This involves a bunch of line
continuation and line concatenation characters be used.
The loop will look something like this:

IDL> FOR j=0,4 DO BEGIN $
IDL> Print, j & $
IDL> Print, j*2 & $
IDL> ENDFOR

This is such a pain in the neck to write that no one
bothers. (Plus, if you make a typing mistake on *any*
line, you have to go back to the beginning; you can't
just fix the offending line.) Most people put this kind
of loop into a program unit of some type. For example,
you could put this loop into a main-level program by
writing it like this in a file:

FOR j=0,4 DO BEGIN
Print, j
Print, j*2
ENDFOR
END

Notice the final END at the end of the file. Name this
file "doloop.pro". To run the loop, type this:

IDL> .RUN doloop

This command actually compiles the FOR loop as a
single statement before it is run, so you don't
have to worry about line continuation and line
concatenation characters. The compiler is MUCH
smarter than the interpreter. :-)

If you want to run a compiled main-level program again,
all you have to do is this:

IDL> .Go

Another alternative is to put the loop into an IDL
procedure. All you need to do is add a procedure
definition line to the DOLOOP program, like this:

PRO DOLOOP
FOR j=0,4 DO BEGIN
Print, j
Print, j*2
ENDFOR
END

To compile and run this program you do this:

IDL> .Compile doloop
IDL> doloop

Thanks for asking this question. A lot of people
give up before admitting they don't know something. :-)

Good luck with your programming!

Cheers,

David

----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438, Toll-Free Book Orders: 1-888-461-0155
Coyote's Guide to IDL Programming: http://www.dfanning.com/

Note: A copy of this article was e-mailed to the original poster.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: clipboard objects and postscript (unix)
Next Topic: IDL and LAPACK

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 15:52:06 PDT 2025

Total time taken to generate the page: 0.48093 seconds