Re: Help with Nested FOR Loop [message #42038] |
Fri, 10 December 2004 16:10 |
Y.T.
Messages: 25 Registered: December 2004
|
Junior Member |
|
|
coold wrote:
> The following code gives me syntax error for the last two endfor
> statements. I am trying to use the nested for loop to print the value
> of x. I have tried &$ on the 6th and 7th while $ on 1 and 2.
> Any help would be appreciated
>
> 1 for i = 0, 20 do begin
> 2 for j = 0, 20 do begin
> 3 for k = 0, 5 do b[0,k] = 0.5^2
> 4 funct_addnumbers, a,b,x ; where x is the result
> 5 print,x
> 6 endfor
> 7 endfor
>
At the comand prompt, each line is compiled individually.
Since nobody has mentioned it yet: you could enter ".run" at the
command prompt, then enter the whole thing up there, then enter "end".
That will do the same thing as dropping the whole thing into a file,
ending the file with "end" and then calling ".run filename".
I am assuming "funct_addunumbers" is your own creation and would like
to point you to the very handy "function" and "return" statements that
should enable you to turn your stuff into something like
print, funct_addnumbers(a,b)
...
cordially
Y.T.
--
Remove YourClothes before you email me.
|
|
|
Re: Help with Nested FOR Loop [message #42039 is a reply to message #42038] |
Fri, 10 December 2004 16:07  |
Y.T.
Messages: 25 Registered: December 2004
|
Junior Member |
|
|
coold wrote:
> The following code gives me syntax error for the last two endfor
> statements. I am trying to use the nested for loop to print the value
> of x. I have tried &$ on the 6th and 7th while $ on 1 and 2.
> Any help would be appreciated
>
> 1 for i = 0, 20 do begin
> 2 for j = 0, 20 do begin
> 3 for k = 0, 5 do b[0,k] = 0.5^2
> 4 funct_addnumbers, a,b,x ; where x is the result
> 5 print,x
> 6 endfor
> 7 endfor
>
At the comand prompt, each line is compiled individually.
Since nobody has mentioned it yet: you could enter ".run" at the
command prompt, then enter the whole thing up there, then enter "end".
That will do the same thing as dropping the whole thing into a file,
ending the file with "end" and then calling ".run filename".
I am assuming "funct_addunumbers" is your own creation and would like
to point you to the very handy "function" and "return" statements that
should enable you to turn your stuff into something like
print, funct_addnumbers(a,b)
...
cordially
Y.T.
--
Remove YourClothes before you email me.
|
|
|
Re: Help with Nested FOR Loop [message #42040 is a reply to message #42039] |
Fri, 10 December 2004 13:34  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
coold writes:
> The following code gives me syntax error for the last two endfor
> statements. I am trying to use the nested for loop to print the value
> of x. I have tried &$ on the 6th and 7th while $ on 1 and 2.
> Any help would be appreciated
>
> for i = 0, 20 do begin
> for j = 0, 20 do begin
> for k = 0, 5 do b[0,k] = 0.5^2
> funct_addnumbers, a,b,x ; where x is the result
> print,x
> endfor
> endfor
Slap this code into a file, add another END at the
bottom of the file, name the file "myloop.pro", then
compile the program:
IDL> .compile myloop
Then, to run the loop, type .GO:
IDL> .go
Don't try to build loops at the IDL command line. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Help with Nested FOR Loop [message #42042 is a reply to message #42040] |
Fri, 10 December 2004 13:29  |
KM
Messages: 29 Registered: October 2004
|
Junior Member |
|
|
On Fri, 10 Dec 2004, coold wrote:
> The following code gives me syntax error for the last two endfor
> statements. I am trying to use the nested for loop to print the
> value of x. I have tried &$ on the 6th and 7th while $ on 1 and 2.
> Any help would be appreciated
>
> 1 for i = 0, 20 do begin
> 2 for j = 0, 20 do begin
> 3 for k = 0, 5 do b[0,k] = 0.5^2
> 4 funct_addnumbers, a,b,x ; where x is the result
> 5 print,x
> 6 endfor
> 7 endfor
We recommend that you do not try to type such complex stuff with
loops at the command line. Put it in a file and then run the files.
If you don't want to use an extra file, check out the .com command
Better yet, type the above in emacs, highlight it, and then "C-c C-d
C-e" it
However, if you wanted to do it all at the CLI
for i = 0, 20 do begin $
for j = 0, 20 do begin $
for k = 0, 5 do print, k &$
print, "foo" &$
endfor &$
endfor
But please, don't do this.
-k.
|
|
|