# How can I execute a sequence of statements interactively?

I'm fairly new to Mathematica. Suppose I have the following function:

f[x_Integer] := Module[{y, z, r},
y = 5;
z = 10;
r = x + y + z;
r
];


and I would like to halt the execution after each of the statements y = 5, z = 10 and r = x + y + z, and resume only after I press a key. (In other words, I'm looking for something like Console.ReadLine() in C# or getline() in C++.) Is there an easy way to do this in Mathematica?

-
I think Input[] does the trick. Is the the idiomatic way of implementing the desired outcome? – Shredderroy Sep 9 '13 at 4:12
Maybe by using built-in debugger? - see here – Vitaliy Kaurov Sep 9 '13 at 4:14
I will certainly look into that. Thank you very much. – Shredderroy Sep 9 '13 at 5:58
@Shredderroy A natural way is to keep open an extra notebook in which to run the code pieces you want to check. – Alexei Boulbitch Sep 9 '13 at 7:47

A fairly crude way to do this is to use e.g. DialogInput or friends, but then you have to intersperse your code with a lot of unnecessary lines:

f[x_Integer] := Module[{y, z, r}, y = 5;
DialogInput["Proceed with z = 10;\n{y,z,r} = " <> ToString@{y, z, r}];
z = 10;
DialogInput["Proceed with r = x + y + z;\n{y,z,r} = " <> ToString@{y, z, r}];
r = x + y + z;
DialogInput["Proceed with r\n{y,z,r} = " <> ToString@{y, z, r}];
r];

f[1]

-
this is nice idea..! – Rorschach Sep 9 '13 at 9:59
Thank you very much. I will use this for now, until I am ready to spring for Workbench. – Shredderroy Sep 9 '13 at 21:51