f



how to have a while inside a for inside a while :(

so, its like the inception movie, but i really need this, i know its easy but i cant figure it out
i am working with FEM and have to track one particle, every element has a unique velocity so i need them to update when they cross from one element to another

so its like this
%%%%%%%%%%%%%%%%%%%%%%%%%
dox=0;
doy=5;

  while (dx<=2.8) || (dy>=4.8)
    for i=1:5
        while dx<=(a*i)
        dx=dox+t*dhdx(141+i) % al pasar a i =2 el tiempo debe empezar de 0
        dy=doy+t*dhdy(141+i)
        dxVector=[dxVector; dx];
        dyVector=[dyVector; dy];
        dox=dx;
        doy=dy;
        t=t+1;
        tVector=[tVector; t]; %%YA AFINADO (+1).
        end
      end
    end
%%%%%%%%%%%%%%%%%%%%%%%%%%

the while inside works fine, the for work fine too, but i want to start always with the frist while, he is my real condition.
so when the particles cross the (dx<=2.8) || (dy>=4.8) (one or the another condition)

but what its does, that he finishe the for, and them goes to the upper while.
i tried using break, continue.

tnx!
0
juan
10/9/2015 9:51:03 PM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader. Post Follow

1 Replies
3887 Views

Similar Articles

[PageSpeed] 25

On 10/9/2015 4:51 PM, juan correa wrote:
> so, its like the inception movie, but i really need this, i know its easy but i cant figure it out
> i am working with FEM and have to track one particle, every element has a unique velocity so i need them to update when they cross from one element to another
>
> so its like this
> %%%%%%%%%%%%%%%%%%%%%%%%%
> dox=0;
> doy=5;
>
>    while (dx<=2.8) || (dy>=4.8)
>      for i=1:5
>          while dx<=(a*i)
>          dx=dox+t*dhdx(141+i) % al pasar a i =2 el tiempo debe empezar de 0
>          dy=doy+t*dhdy(141+i)
>          dxVector=[dxVector; dx];
>          dyVector=[dyVector; dy];
>          dox=dx;
>          doy=dy;
>          t=t+1;
>          tVector=[tVector; t]; %%YA AFINADO (+1).
>          end
>        end
>      end
> %%%%%%%%%%%%%%%%%%%%%%%%%%
>
> the while inside works fine, the for work fine too, but i want to start always with the frist while, he is my real condition.
> so when the particles cross the (dx<=2.8) || (dy>=4.8) (one or the another condition)
>
> but what its does, that he finishe the for, and them goes to the upper while.
> i tried using break, continue.
>
> tnx!
>


it is hard to understand what you are asking. You could have
made a simple example.

You wrote

while some_condition
    for i=1:5
        while some_other_condition
              ...
        end
    end
end

The above makes little sense, since the for loop will iterate 5 times
any way.

If you mean you wanted an inner loop that iterates at most 5 times,
but breaks when the inner condition is met, you can do

while some_condition
   i=1;
   while some_other_condition && i<=5
     ...stuff that could change some_other_condition to be false
     i=i+1;
   end
end


--Nasser


0
Nasser
10/9/2015 10:14:43 PM
Reply: