Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'For loops within while loops' topicStudent Support Forum > General > Archives > "For loops within while loops"

Next Comment >Help | Reply To Topic
Author Comment/Response
Jessica
02/25/13 03:19am

I want to run a while loop multiple times with a new constant inside it.

I have tried putting the while loop within a for or do loop, but it the while loop is iterated with the same original constant value each time. Here is a very simplified version of what I have tried:

tMatrix = {t}; xMatrix = {x};
Do[While[0 <= t < 6, {t = t + 0.5, x = i + t,
tMatrix = Append[tMatrix, t], xMatrix = Append[xMatrix, x]}];
Print[xMatrix], {i, 0, 10, 2}]

or a for loop in place of the Do.

Either way, I get a set of matrices back, but they all have the same values. I want each new matrix to be the while loop evaluated at the NEW i. Can I accomplish this somehow??

URL: ,

Subject (listing for 'For loops within while loops')
Author Date Posted
For loops within while loops Jessica 02/25/13 03:19am
Re: For loops within while loops Bill Simpson 02/25/13 6:47pm
Next Comment >Help | Reply To Topic