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

Post Reply:
Name:
Email Address:

Please send email when my message is replied to.

Url (optional):
Subject:
Message: view original message?
Attachment (optional):
Please answer this:1+1 =



Original Message (ID '367384') By Bill Simpson:
Problems: t was not initialized so your While never ran. Mathematica uses {} only to make lists, never to group statements the way other languages does. So I tried this modification of your code: In[1]:= tMatrix={t}; xMatrix={x}; Do[ Print["i=",i]; t=0; While[0≤t<6, Print["t=",t]; t=t+0.5; x=i+t; tMatrix=Append[tMatrix,t]; xMatrix=Append[xMatrix,x] ]; Print[xMatrix], {i,0,10,2} ] From In[1]:= i=0 From In[1]:= t=0 From In[1]:= t=0.5 From In[1]:= t=1. From In[1]:= t=1.5 From In[1]:= t=2. From In[1]:= t=2.5 From In[1]:= t=3. From In[1]:= t=3.5 From In[1]:= t=4. From In[1]:= t=4.5 From In[1]:= t=5. From In[1]:= t=5.5 From In[1]:= {0.5,0.5,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.,5.5,6.} From In[1]:= i=2 From In[1]:= t=0 From In[1]:= t=0.5 From In[1]:= t=1. From In[1]:= t=1.5 From In[1]:= t=2. From In[1]:= t=2.5 From In[1]:= t=3. From In[1]:= t=3.5 From In[1]:= t=4. From In[1]:= t=4.5 From In[1]:= t=5. From In[1]:= t=5.5 From In[1]:= {0.5,0.5,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.,5.5,6.,2.5,3.,3.5,4.,4.5,5.,5.5,6.,6.5,7.,7.5,8.} From In[1]:= i=4 From In[1]:= t=0 From In[1]:= t=0.5 From In[1]:= t=1. From In[1]:= t=1.5 From In[1]:= t=2. From In[1]:= t=2.5 From In[1]:= t=3. From In[1]:= t=3.5 From In[1]:= t=4. From In[1]:= t=4.5 From In[1]:= t=5. From In[1]:= t=5.5 From In[1]:= {0.5,0.5,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.,5.5,6.,2.5,3.,3.5,4.,4.5,5.,5.5,6.,6.5,7.,7.5,8.,4.5,5.,5.5,6.,6.5,7.,7.5,8.,8.5,9.,9.5,10.} etc. etc. etc. I'm guessing you want t initialized some other way, perhaps outside the Do, perhaps not, and I can't guess what that should be. But this should give you a start.