Re: Begin statement [message #3259 is a reply to message #3258] |
Thu, 05 January 1995 10:45   |
gurman
Messages: 82 Registered: August 1992
|
Member |
|
|
In article <3efcu3$6br@post.gsfc.nasa.gov>,
thompson@orpheus.nascom.nasa.gov (William Thompson) wrote:
> hartl@clouzot.imo.physik.uni-muenchen.de (Ingmar Hartl) writes:
>
>> In article <hahn.74.00145964@hrz.th-darmstadt.de>
hahn@hrz.th-darmstadt.de (Norbert Hahn) writes:
>>> and it looks as if begin is immediately followed by end:
>>> IDL> repeat begin
>>> All rights reserved. Unauthorized reproduction prohibited.
>>> & END
>>> ^
>>> % Syntax error.
>
>> Same happened to me.
>
>> It worked, after I wrote a procedure with this statements.
>
>> I think, it is only allowed to use BEGIN and END statements
>> in procedures and functions. I found nothing to this point
>> in the User's Guide...
>
>> Ingmar Hartl.
>
> Actually, on can use BEGIN and END statements from the command line, but one
> has to fit in the entire command onto a single command line, e.g.
>
> IDL> FOR I=1,10 DO BEGIN & PRINT,I & HELP,I & ENDFOR
In fact, on the command line, one can even omit the END[FOR] --- as
the original poster had it:
IDL> for i = 0, 9 do begin & print,i & help,i
(I never knew it worked until David Stern did it while showing me
something or other.)
Joe Gurman
>
> (It actually doesn't matter if one uses END or ENDFOR. Always remembering to
> use ENDFOR, ENDIF, ENDWHILE, etc. leads to more readable code and makes it
> easier for IDL to point out where any errors might occur.)
>
> If one only wants a single statement within a FOR loop, then one can omit the
> BEGIN and ENDFOR statements, e.g.
>
> IDL> FOR I=1,10 DO PRINT,I
>
> If one can't fit the entire loop onto a single line, then one needs to write a
> procedure, either by editing a file or by using .RUN, e.g.
>
> IDL> .RUN
> - FOR I=1,10 DO BEGIN
> - PRINT, I
> - HELP, I
> - ENDFOR
> - END
>
> William Thompson
--
J.B. Gurman / Solar Physics Branch/ NASA Goddard Space Flight Center/
Greenbelt MD 20771 USA / gurman@uvsp.gsfc.nasa.gov
| Federal employees are still prohibited from holding opinions while|
| at work. Therefore, any opinions expressed herein are somebody |
| else's. |
|
|
|