# While loop syntax in Mathematica 9

Posted 10 years ago
11498 Views
|
2 Replies
|
2 Total Likes
|
 Hi There,I am trying to write a loop that will carry out a series of individual calculations iteratively. The loop will need to be something like a DoWhile so that I can run once completely through before I check the test statement. Pseudo code is below. //Define constants  x=0.055 Degree; Epsilon = 0.001; sightd = 100; delta = 0.0005 Degree;  Start loop here  //Compute solution to equation once first test statement //to be checked starting second iteration angsol = NDSolve[Equations]//set new function to solution of NDSOLVEIn[267]:= xang[t_] := xa[t] /. angsol[[1, 1]]//Find critical valueIn[269]:= tang = FindRoot[xang[t] == sightd, {t, 0.1}];//IncrementIn[265]:= x = x + delta;Restart LoopDoes anyone have any suggestions? I know steps work individually, but now I need to string them together so the program will loop and find the solution.Thanks in advanceCole
2 Replies
Sort By:
Posted 10 years ago
 I might be misunderstanding your description, but this seems like a problem well-suited for Nest or NestWhile.
Posted 10 years ago
 Update:: SolvedI was able to solve this using a compound expression (;) inside a while loop structure. I had to change my check statement to prevent an infinite loop, but added an if statement break.RegardsCole