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

Home » Public Forums » archive » Re: FOR loop ends one above where it's supposed to
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: FOR loop ends one above where it's supposed to [message #71125 is a reply to message #71124] Wed, 02 June 2010 08:57 Go to previous messageGo to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Jun 1, 8:26 pm, Bulgakovv <alex.ph.sjog...@gmail.com> wrote:
> Maybe there are previous posts about this, but I tried to google
> around without any success so I'll throw the question out.
>
> When I make a FOR loop from for example 0 to 5, the counter ends on
> the value one step above what I stated. Here's an example:
>
>> for i =0,5 do print,i
>
>        0
>        1
>        2
>        3
>        4
>        5>print,i
>
>        6
>
> Is this how it's supposed to be in IDL? To me it seems a little bit
> weird, why would the FOR loop count one extra step in the end? Took me
> a couple of hours to realize what was going on in my code as I took
> for granted this was not the case, so now I'm interested in
> understanding why IDL is behaving like this. Thanks and sorry if
> reposting!

While people here gave a logical explanation as to what is happening,
I would say that the *safest* practice in your programming is to not
use the for loop index variable ("i" in this case) for anything else
in your program. That will make the code much easier to write, read
and understand.

Ciao,
Paolo
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: IDL for planetary photometry
Next Topic: Re: dealing with arguments

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

Current Time: Wed Oct 08 19:30:01 PDT 2025

Total time taken to generate the page: 0.00412 seconds