Hi Amaru,
Are you running that code in a file or directly in the IDL command line? If it is the IDL command line everything needs to be one line and you can't directly type "for i=-0,5 do begin... the rest of your loopon other lines" because that extends more than one line. The same rule applies for a batch file which can be called with the @ symbol before the file name. Instead, you would need to use the "$" to indicate that it continues on the next line as one command. This is how that would look:
for i=0,4 do $
print, i
The reason that i becomes 5 is because this gets evaluated first "for i = 0, 4 DO BEGIN" and this loop exits when i becomes 5 (which is expected and how it works). Then, as a completely separate command, IDL gets "PRINT, i" which will return a 5 because IDL is no longer in the original loop. You then get a syntax error because all IDL gets is "endfor" which is not a command by itself.
|