<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295</link>
    <title>MATLAB Central Newsreader - do while</title>
    <description>Feed for thread: do while</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 15 May 2008 08:43:02 -0400</pubDate>
      <title>do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432177</link>
      <author>Deo </author>
      <description>is there a matlab command equivalent to the C do while&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 09:14:02 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432182</link>
      <author>French Caro</author>
      <description>"Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g0gt2m$h3q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; is there a matlab command equivalent to the C do while&lt;br&gt;
help while&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 09:23:02 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432184</link>
      <author>Deo </author>
      <description>"French Caro " &amp;lt;caro95470@nospam.free.fr&amp;gt; wrote in message &lt;br&gt;
&amp;lt;g0gusq$425$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;g0gt2m$h3q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; is there a matlab command equivalent to the C do while&lt;br&gt;
&amp;gt; help while&lt;br&gt;
That was the first place I looked and there was nothing &lt;br&gt;
that could help me&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 10:16:02 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432197</link>
      <author>John D'Errico</author>
      <description>"Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;g0gvdm$5tj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "French Caro " &amp;lt;caro95470@nospam.free.fr&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;lt;g0gusq$425$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; "Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;g0gt2m$h3q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; is there a matlab command equivalent to the C do while&lt;br&gt;
&amp;gt; &amp;gt; help while&lt;br&gt;
&amp;gt; That was the first place I looked and there was nothing &lt;br&gt;
&amp;gt; that could help me&lt;br&gt;
&lt;br&gt;
Then you did not look hard enough.&lt;br&gt;
&lt;br&gt;
Look again. Read the examples.&lt;br&gt;
&lt;br&gt;
John&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 11:44:02 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432211</link>
      <author>French Caro</author>
      <description>"Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g0gvdm$5tj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "French Caro " &amp;lt;caro95470@nospam.free.fr&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;lt;g0gusq$425$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; "Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;g0gt2m$h3q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; is there a matlab command equivalent to the C do while&lt;br&gt;
&amp;gt; &amp;gt; help while&lt;br&gt;
&amp;gt; That was the first place I looked and there was nothing &lt;br&gt;
&amp;gt; that could help me&lt;br&gt;
&lt;br&gt;
Can you explain more ?&lt;br&gt;
I don't know about "do while" in C but I think that it&lt;br&gt;
should be the same as "while" in MATLAB.&lt;br&gt;
&lt;br&gt;
Caroline&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 13:14:04 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432229</link>
      <author>CandyGirl</author>
      <description>Yes there is,&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
A=5&lt;br&gt;
B=2&lt;br&gt;
&lt;br&gt;
while(A &amp;gt; B)&lt;br&gt;
C = (A+B)/2&lt;br&gt;
B=B+1&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
hope that helped&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 14:31:02 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432260</link>
      <author>Dave Robinson</author>
      <description>CandyGirl &amp;lt;Rasha@dqnetwork.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;16944196.1210857274898.JavaMail.jakarta@nitrogen.mathforum.&lt;br&gt;
org&amp;gt;...&lt;br&gt;
&amp;gt; Yes there is,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A=5&lt;br&gt;
&amp;gt; B=2&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; while(A &amp;gt; B)&lt;br&gt;
&amp;gt; C = (A+B)/2&lt;br&gt;
&amp;gt; B=B+1&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; hope that helped&lt;br&gt;
&lt;br&gt;
The 'C' family has both &lt;br&gt;
while(test)&lt;br&gt;
{&lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
and &lt;br&gt;
&lt;br&gt;
do&lt;br&gt;
{&lt;br&gt;
&lt;br&gt;
}while(test)&lt;br&gt;
&lt;br&gt;
they are different. With the while loop, if test is false &lt;br&gt;
the code in the curlies is bypassed, if it is true it is &lt;br&gt;
continuously looped until it becomes false, With the do - &lt;br&gt;
while construct the code in the curlies is always executed &lt;br&gt;
at least once, then the value of test controls whether the &lt;br&gt;
code is reexecuted, the two constructs are slightly &lt;br&gt;
different animals.&lt;br&gt;
&lt;br&gt;
There is probably a much better way of doing it, but &lt;br&gt;
perhaps the following abomination might give you the &lt;br&gt;
functionality you need.&lt;br&gt;
&lt;br&gt;
while(true) %Loop forever&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Your code&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!test)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;endif&lt;br&gt;
endwhile&lt;br&gt;
&lt;br&gt;
Regards&lt;br&gt;
&lt;br&gt;
Dave Robinson&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 14:39:03 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432262</link>
      <author>Jos </author>
      <description>"Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g0gt2m$h3q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; is there a matlab command equivalent to the C do while&lt;br&gt;
&lt;br&gt;
There is a subtle difference between a "do-while" loop and&lt;br&gt;
"while" loop:&lt;br&gt;
do-while executes the loop at least once, whereas while may&lt;br&gt;
skip the loop altogether&lt;br&gt;
&lt;br&gt;
A work-around:&lt;br&gt;
&lt;br&gt;
% an infinite for-loop&lt;br&gt;
for i=1:Inf,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;% ... code ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;if ~condition, &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break ; % break out of the for-loop&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
hth&lt;br&gt;
Jos&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 14:52:02 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432264</link>
      <author>Bryan </author>
      <description>Couldn't you also just do the following:&lt;br&gt;
&lt;br&gt;
%execute commands&lt;br&gt;
&lt;br&gt;
while (test)&lt;br&gt;
&amp;nbsp;&amp;nbsp;%execute commands&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
By executing the code first outside the while loop, you're &lt;br&gt;
ensuring that it gets executed once even if test is never &lt;br&gt;
true, just as a do-while loop will do.  You'll probably &lt;br&gt;
have to change the (test) part of the loop a bit, but you &lt;br&gt;
should be able to get the functionality you want with a &lt;br&gt;
simple while loop.&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 16:40:19 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432281</link>
      <author>Steve Amphlett</author>
      <description>"Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;g0gt2m$h3q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; is there a matlab command equivalent to the C do while&lt;br&gt;
&lt;br&gt;
Another abomination:&lt;br&gt;
&lt;br&gt;
first=true;&lt;br&gt;
while(condition || first)&lt;br&gt;
&lt;br&gt;
% stuff&lt;br&gt;
&lt;br&gt;
first=false;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 16:57:42 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432284</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g0hp1j$k93$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
Steve Amphlett &amp;lt;Firstname.Lastname@Where-I-Work.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;"Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt;&amp;lt;g0gt2m$h3q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; is there a matlab command equivalent to the C do while&lt;br&gt;
&lt;br&gt;
&amp;gt;Another abomination:&lt;br&gt;
&lt;br&gt;
&amp;gt;first=true;&lt;br&gt;
&amp;gt;while(condition || first)&lt;br&gt;
&lt;br&gt;
&amp;gt;% stuff&lt;br&gt;
&lt;br&gt;
&amp;gt;first=false;&lt;br&gt;
&amp;gt;end&lt;br&gt;
&lt;br&gt;
Evaluating condition might have side effects. To match do while&lt;br&gt;
those side effects should not be triggered on the first trip.&lt;br&gt;
Therefore the above should be rewritten to&lt;br&gt;
&lt;br&gt;
first=true;&lt;br&gt;
while(first || condition)&lt;br&gt;
% stuff&lt;br&gt;
first=false;&lt;br&gt;
end&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;So you found your solution&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;What will be your last contribution?&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;-- Supertramp (Fool's Overture)&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 17:47:51 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432309</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
"Walter Roberson" &amp;lt;roberson@ibd.nrc-cnrc.gc.ca&amp;gt; wrote in message &lt;br&gt;
news:g0hq26$q1o$1@canopus.cc.umanitoba.ca...&lt;br&gt;
&amp;gt; In article &amp;lt;g0hp1j$k93$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
&amp;gt; Steve Amphlett &amp;lt;Firstname.Lastname@Where-I-Work.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;&amp;gt;"Deo " &amp;lt;spliers@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt;&amp;gt;&amp;lt;g0gt2m$h3q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; is there a matlab command equivalent to the C do while&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;Another abomination:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;first=true;&lt;br&gt;
&amp;gt;&amp;gt;while(condition || first)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;% stuff&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;first=false;&lt;br&gt;
&amp;gt;&amp;gt;end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Evaluating condition might have side effects. To match do while&lt;br&gt;
&amp;gt; those side effects should not be triggered on the first trip.&lt;br&gt;
&amp;gt; Therefore the above should be rewritten to&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; first=true;&lt;br&gt;
&amp;gt; while(first || condition)&lt;br&gt;
&amp;gt; % stuff&lt;br&gt;
&amp;gt; first=false;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
Alternately, you could use this:&lt;br&gt;
&lt;br&gt;
done = false;&lt;br&gt;
while ~done&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;% your code&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ~condition&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;done = true;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
The condition isn't evaluated until after the loop has executed at least &lt;br&gt;
once, and it's evaluated after the loop execution each subsequent time.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 17:57:01 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432317</link>
      <author>helper </author>
      <description>&amp;gt; Alternately, you could use this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; done = false;&lt;br&gt;
&amp;gt; while ~done&lt;br&gt;
&amp;gt;     % your code&lt;br&gt;
&amp;gt;     if ~condition&lt;br&gt;
&amp;gt;         done = true;&lt;br&gt;
&amp;gt;     end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Or another method&lt;br&gt;
&lt;br&gt;
while true&lt;br&gt;
&amp;nbsp;&amp;nbsp;% your code&lt;br&gt;
&amp;nbsp;&amp;nbsp;if condition&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 16 May 2008 13:45:03 -0400</pubDate>
      <title>Re: do while</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169295#432496</link>
      <author>Dave Robinson</author>
      <description>"helper " &amp;lt;spamless@nospam.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g0hthd$m6b$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Alternately, you could use this:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; done = false;&lt;br&gt;
&amp;gt; &amp;gt; while ~done&lt;br&gt;
&amp;gt; &amp;gt;     % your code&lt;br&gt;
&amp;gt; &amp;gt;     if ~condition&lt;br&gt;
&amp;gt; &amp;gt;         done = true;&lt;br&gt;
&amp;gt; &amp;gt;     end&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Or another method&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; while true&lt;br&gt;
&amp;gt;   % your code&lt;br&gt;
&amp;gt;   if condition&lt;br&gt;
&amp;gt;     break&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
Am I missing something - how does this differ from my&lt;br&gt;
original abomination?&lt;br&gt;
&lt;br&gt;
Regards&lt;br&gt;
&lt;br&gt;
Dave Robinson&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
