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

Home » Public Forums » archive » Re: Starting a for loop within an if loop
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: Starting a for loop within an if loop [message #57637 is a reply to message #57632] Thu, 20 December 2007 03:19 Go to previous messageGo to previous message
Carsten Lechte is currently offline  Carsten Lechte
Messages: 124
Registered: August 2006
Senior Member
Mat Smith wrote:
> Basically, I need something like:
>
> IF keyword_set(mc) THEN BEGIN
> FOR i=0,n-1 DO BEGIN
> t=d[i]
> ENDIF
>
> and later in the program
>
> IF keyword_set(mc) THEN BEGIN
> ENDFOR
> ENDIF

Others have pointed out some solutions for your problem, so I
will comment on why your approach must fail.

The reason is: Computers do not understand programming languages.

Source code in IDL, C, perl etc. must be translated into bit
patterns (the "machine code") that the CPU of the computer can
use directly. The abstract concept of a FOR loop is translated
into a certain set of machine instructions and then executed.
Fro this to work, the loop has to be present in the source code
in its entirety.

In the source code, i.e. the stuff that the human writes, the
FOR loop is often represented by several units/lines of code:
The "FOR ...", the code that is to be looped over, and the
termination statement "ENDFOR". In most programming languages,
these are all obligatory components that have to be present at
the time that the code is translated into machine code (i.e.
during the compilation phase.)

What you tried was to make conditional statements that can only
be evaluated during run-time, i.e. after the compilation phase --
but the compiler does not get that far. Your only hope is to use
the FOR loop as a complete unit inside your conditional statements.
That way, the compiler can translate the whole loop, and during
run-time, the program can decide if the loop should be run or not.

I find it hard to express these concepts (other than saying
"compilers do not work like that.")

Note that in C, you actually can use the preprocessor to do
something like that, but this works because the conditionals
are decided before compilation, and the actual compiler either
sees the complete FOR loop, or none at all (or a loop with one
half missing, if you messed up the #ifdef's...)


chl
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Debugging in IDL 7
Next Topic: Re: IDL 7 on Ubuntu (probably also relevant to Fedora 8)

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

Current Time: Fri Oct 10 15:25:05 PDT 2025

Total time taken to generate the page: 1.82338 seconds