I have a simple function:
f[x0_,y0_]:= Module[{x=x0,y=y0},For[i=0,i<2,i++;Print[x],Print[x+y]];]
So when I call it:
f[2,3]
I get:
5
2
5
2
Why not:
2
5
2
5
as expected? Also my indentation of - or + don't seem to format?
|
I have a simple function:
So when I call it: I get:
Why not:
as expected? Also my indentation of - or + don't seem to format? |
||||
|
Your first
You can put it all in the body like (note position of commas and semicolons):
I recommend you actively try to avoid And check the other links in this popular answer under the section Basic advices for people new to Mathematica |
||||
|
|
f[x0_, y0_] := Module[{x = x0, y = y0},For[i = 0, i < 2,i++;Print[x]; Print[x + y]];]. This works as you expect it to work. – Öskå Nov 24 '12 at 12:08Printfunction will print whether you add a;in the end or not. Although I have no clue why that comma changes the order. – Öskå Nov 24 '12 at 12:25