"French Caro " <caro95470@nospam.free.fr> wrote in message
<g0gusq$425$1@fred.mathworks.com>...
> "Deo " <spliers@hotmail.com> wrote in message
> <g0gt2m$h3q$1@fred.mathworks.com>...
> > is there a matlab command equivalent to the C do while
> help while
That was the first place I looked and there was nothing
that could help me
"Deo " <spliers@hotmail.com> wrote in message
<g0gvdm$5tj$1@fred.mathworks.com>...
> "French Caro " <caro95470@nospam.free.fr> wrote in message
> <g0gusq$425$1@fred.mathworks.com>...
> > "Deo " <spliers@hotmail.com> wrote in message
> > <g0gt2m$h3q$1@fred.mathworks.com>...
> > > is there a matlab command equivalent to the C do while
> > help while
> That was the first place I looked and there was nothing
> that could help me
"Deo " <spliers@hotmail.com> wrote in message
<g0gvdm$5tj$1@fred.mathworks.com>...
> "French Caro " <caro95470@nospam.free.fr> wrote in message
> <g0gusq$425$1@fred.mathworks.com>...
> > "Deo " <spliers@hotmail.com> wrote in message
> > <g0gt2m$h3q$1@fred.mathworks.com>...
> > > is there a matlab command equivalent to the C do while
> > help while
> That was the first place I looked and there was nothing
> that could help me
Can you explain more ?
I don't know about "do while" in C but I think that it
should be the same as "while" in MATLAB.
CandyGirl <Rasha@dqnetwork.com> wrote in message
<16944196.1210857274898.JavaMail.jakarta@nitrogen.mathforum.
org>...
> Yes there is,
>
>
> A=5
> B=2
>
> while(A > B)
> C = (A+B)/2
> B=B+1
> end
>
> hope that helped
The 'C' family has both
while(test)
{
}
and
do
{
}while(test)
they are different. With the while loop, if test is false
the code in the curlies is bypassed, if it is true it is
continuously looped until it becomes false, With the do -
while construct the code in the curlies is always executed
at least once, then the value of test controls whether the
code is reexecuted, the two constructs are slightly
different animals.
There is probably a much better way of doing it, but
perhaps the following abomination might give you the
functionality you need.
while(true) %Loop forever
Your code
if(!test)
break;
endif
endwhile
"Deo " <spliers@hotmail.com> wrote in message
<g0gt2m$h3q$1@fred.mathworks.com>...
> is there a matlab command equivalent to the C do while
There is a subtle difference between a "do-while" loop and
"while" loop:
do-while executes the loop at least once, whereas while may
skip the loop altogether
A work-around:
% an infinite for-loop
for i=1:Inf,
% ... code ...
if ~condition,
break ; % break out of the for-loop
end
end
By executing the code first outside the while loop, you're
ensuring that it gets executed once even if test is never
true, just as a do-while loop will do. You'll probably
have to change the (test) part of the loop a bit, but you
should be able to get the functionality you want with a
simple while loop.
In article <g0hp1j$k93$1@fred.mathworks.com>,
Steve Amphlett <Firstname.Lastname@Where-I-Work.com> wrote:
>"Deo " <spliers@hotmail.com> wrote in message
><g0gt2m$h3q$1@fred.mathworks.com>...
>> is there a matlab command equivalent to the C do while
>Another abomination:
>first=true;
>while(condition || first)
>% stuff
>first=false;
>end
Evaluating condition might have side effects. To match do while
those side effects should not be triggered on the first trip.
Therefore the above should be rewritten to
first=true;
while(first || condition)
% stuff
first=false;
end
--
So you found your solution
What will be your last contribution?
-- Supertramp (Fool's Overture)
"Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca> wrote in message
news:g0hq26$q1o$1@canopus.cc.umanitoba.ca...
> In article <g0hp1j$k93$1@fred.mathworks.com>,
> Steve Amphlett <Firstname.Lastname@Where-I-Work.com> wrote:
>>"Deo " <spliers@hotmail.com> wrote in message
>><g0gt2m$h3q$1@fred.mathworks.com>...
>>> is there a matlab command equivalent to the C do while
>
>>Another abomination:
>
>>first=true;
>>while(condition || first)
>
>>% stuff
>
>>first=false;
>>end
>
> Evaluating condition might have side effects. To match do while
> those side effects should not be triggered on the first trip.
> Therefore the above should be rewritten to
>
> first=true;
> while(first || condition)
> % stuff
> first=false;
> end
Alternately, you could use this:
done = false;
while ~done
% your code
if ~condition
done = true;
end
end
The condition isn't evaluated until after the loop has executed at least
once, and it's evaluated after the loop execution each subsequent time.
"helper " <spamless@nospam.com> wrote in message
<g0hthd$m6b$1@fred.mathworks.com>...
> > Alternately, you could use this:
> >
> > done = false;
> > while ~done
> > % your code
> > if ~condition
> > done = true;
> > end
> > end
>
>
> Or another method
>
> while true
> % your code
> if condition
> break
> end
> end
Am I missing something - how does this differ from my
original abomination?
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.