Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

Thanks in advance for your help.

share|improve this question
    
I think Input[] does the trick. Is the the idiomatic way of implementing the desired outcome? –  Shredderroy Sep 9 '13 at 4:12
1  
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
2  
@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
add comment

1 Answer

up vote 4 down vote accepted

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]
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.