Early on the learning curve: for loops

This is a very basic question, showing I don't understand how Igor works.

I'm trying to familiarize myself with the way Igor works, but I'm lacking certain key information on how to do things. In particular, how to use do loops inline(possible?) or in a Procedure. The following trivial example:

Make/N=4/D xx,yy
xx=1
yy=0
for (ii=1; ii<4; ii+=1)
xx=xx+1
yy=xx*xx
endfor
print xx,yy

gives me an error ('expected wave name, variable name or operation' at the "for" line) when I type in the commands sequentially like Python will let you do. So I presume sequential commands like this aren't allowed.

If I enter the same sequence into a new Procedure window, it compiles OK (ie no error message), and I can save it. But now I need to understand how to invoke/run it.

Igor is sufficiently different than anything I've used before that I can't work out the analogies with what I know. The "Guided Tour" section uses a much more detailed example, which I can emulate but which I can't see how to apply in this simple case.

Help appreciated.
Thanks. Yes, that's a better way to do it, for this trivial example, but I am trying to get a loop working in a much more complex program where the simple approach doesn't work.

I can get do-while working as a Macro:
Macro test()
Make/N=4/D/O xx,yy
xx=1
yy=0
Variable ii=1
do
xx=xx+1
yy=xx*xx
ii+=1
while(ii<4)
print xx,yy
EndMacro

which I can immediately run from the macros menu item. However, for-loops won't run in macros, I find. So I was wondering how to create a procedure rather than a macro (the manuals say procedures are preferred over macros), and then how to run it in the absence of a menu option.

DN
Make sure that your variables are defined in your local functions. In your first post your code should look like this:

function test()
      Make/O/N=4/D xx,yy
      xx=1
      yy=0
      variable ii  //this is missing in your first example
      for (ii=1; ii<4; ii+=1)
         xx=xx+1  //not sure what this should do in a loop
         yy=xx*xx
     endfor
    print xx,yy

end


you can execute this code by typing

test()


into the command line. Check out the chapter IV-3; Programming; User-defined functions of the manual.





Thanks. That's exactly what I needed to know. The problem I face is that Igor is so immensely capable that finding what I'm after in the help system is no simple task!
I recommend that you read chapters IV-1, IV-2 and IV-3 of the Igor Pro manual. This will explain the basics of Igor programming.