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

Home » Public Forums » archive » Re: multi conditional for loops
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: multi conditional for loops [message #20384 is a reply to message #20378] Wed, 21 June 2000 00:00 Go to previous message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
K Mankoff wrote:
>
> Hi *,
> I am interested in coding with a c/c++ style multi-conditional for
> loop.
>
> c++ ex:
> for ( int i = 0; ( ( i < 10 ) && ( j <= 4 ) ); i++ )
> {
> /* do something */
> }
>
> Here is sample IDL code. It runs but produces very interesting
> results. (this is IDL5.3 on Linux RH6.2)
>
> PRO test
> j = 0
> FOR i = 0, ((j LE 4) AND 10) DO BEGIN
> j = j + 2
> PRINT, i, j
> ENDFOR
> END
>
> thanks for any info,
> ken.

The value of a conditional is either 0 or 1. So, the loop will execute
either 1 or 2 times depending on the value of the conditional.
(J < 4) => 1, 1 AND 10 => 0, so the terminating expression is 0 and
the loop should execute once (FOR i=0, 0 DO...). The first and second
expressions are only evaluated before the loop begins, not during its
execution, so even if the condition changes the value used as the limit
will not.

What you need to use is a while loop.

--
-----------------------------------------------------------
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
[Message index]
 
Read Message
Read Message
Previous Topic: Re: very fast spline interp function for heavy oversampling?
Next Topic: Re: Creating a GIF file from a graphics window in IDL

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

Current Time: Fri Oct 10 14:00:59 PDT 2025

Total time taken to generate the page: 0.48370 seconds