X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 29 Apr 2011 07:03 AM by  anon
for loop
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
29 Apr 2011 07:03 AM
    Hello, I wrote a file test.idl with following code inside: for i=1,2 do begin print,i exit The result I get is 3! What did I wrong? Thx in advance Lars

    Deleted User



    New Member


    Posts:
    New Member


    --
    29 Apr 2011 07:22 AM
    Given code does not work for me .... IDL does not compile it. Also, I'm not sure why you are using procedure 'exit'; this will just make IDL save and exit. Back to your case .... The proper way to do for loop: for i=1,2 do begin print,i endfor end this will give you 1 2 The wrong way to do foor loop for i=1,2 do begin end print,i end will give you 3, because the FOR loop iterator (i) is in this case a global variable that made it to 3, loop exited and the value printed is therefor 3 I hope this helps a bit

    Deleted User



    New Member


    Posts:
    New Member


    --
    04 Jul 2011 06:00 AM
    I think I have done the wrong thing to do for loop, that's why I didn't arrive to the correct output. Anyways, thanks for this, it also helps a lot. frances elaine newton
    You are not authorized to post a reply.