<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: for Versus while</title>
	<atom:link href="http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31310</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 05 May 2010 10:54:56 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31310</guid>
		<description>Ali-

Yes, you can do it with while as well.  I suggest ready the help for while and the Getting Started with MATLAB documentation for more information.

--Loren</description>
		<content:encoded><![CDATA[<p>Ali-</p>
<p>Yes, you can do it with while as well.  I suggest ready the help for while and the Getting Started with MATLAB documentation for more information.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ali ahider</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31309</link>
		<dc:creator>ali ahider</dc:creator>
		<pubDate>Wed, 05 May 2010 07:09:21 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31309</guid>
		<description>is it possible the above code with &quot;while command&quot; only.

what happened when there are multiple options like:


&lt;pre&gt;
t = 11;
a = 5;
i = 0;
repeat
inc(i);
until (i = 5) or (t &gt; a)

&lt;/pre&gt;

 Will it be handled with &quot;while&quot; only?

Regards</description>
		<content:encoded><![CDATA[<p>is it possible the above code with &#8220;while command&#8221; only.</p>
<p>what happened when there are multiple options like:</p>
<pre>
t = 11;
a = 5;
i = 0;
repeat
inc(i);
until (i = 5) or (t &gt; a)
</pre>
<p> Will it be handled with &#8220;while&#8221; only?</p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31304</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 04 May 2010 18:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31304</guid>
		<description>Ali-

Since you can compute the steps in advance, you would be best off using a for loop, something like

&lt;pre class=&quot;code&quot;&gt;
for count=4:2:20
   doStuff
end
&lt;/pre&gt;

--Loren</description>
		<content:encoded><![CDATA[<p>Ali-</p>
<p>Since you can compute the steps in advance, you would be best off using a for loop, something like</p>
<pre class="code">
for count=4:2:20
   doStuff
end
</pre>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ali haider</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31303</link>
		<dc:creator>ali haider</dc:creator>
		<pubDate>Tue, 04 May 2010 17:23:19 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31303</guid>
		<description>what is the alternate in MATLAB of command &quot;repeat...until&quot; {as in PASCAL} e.g what is the conversion of this code written in PASCAL:
&lt;pre&gt;
begin
   Count := 4;
   repeat
      Write(&#039;This is in the &#039;);
      Write(&#039;repeat loop, and &#039;);
      Write(&#039;the index is&#039;,Count:4);
      Writeln;
      Count := Count + 2;
   until Count = 20;
   Writeln(&#039; We have completed the loop &#039;);
end.

&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>what is the alternate in MATLAB of command &#8220;repeat&#8230;until&#8221; {as in PASCAL} e.g what is the conversion of this code written in PASCAL:</p>
<pre>
begin
   Count := 4;
   repeat
      Write('This is in the ');
      Write('repeat loop, and ');
      Write('the index is',Count:4);
      Writeln;
      Count := Count + 2;
   until Count = 20;
   Writeln(' We have completed the loop ');
end.
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31184</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 23 Mar 2010 11:18:58 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31184</guid>
		<description>Shruti-

I suggest you read the help for for more carefully.  And also look for the help for the colon operator.  You can assign anything to the loop counter, including a vector that decreases, e.g., 10:-1:1.

--Loren</description>
		<content:encoded><![CDATA[<p>Shruti-</p>
<p>I suggest you read the help for for more carefully.  And also look for the help for the colon operator.  You can assign anything to the loop counter, including a vector that decreases, e.g., 10:-1:1.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shruti</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31183</link>
		<dc:creator>shruti</dc:creator>
		<pubDate>Tue, 23 Mar 2010 06:30:12 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-31183</guid>
		<description>I have a query on a little deviated topic. I am supposed to implement a loop which works on a decremental operator. Apparently the for loop does not work for the same. can you help me. 

what i need to do in for is:

temp = aif(I);
for v = I:1
   if(aif(v)&gt;temp)
      temp=aif(v);
      v = v-1;
   else
      arr = aif(v);
      disp(arr);
   end
end
how do i replace the for loop here?</description>
		<content:encoded><![CDATA[<p>I have a query on a little deviated topic. I am supposed to implement a loop which works on a decremental operator. Apparently the for loop does not work for the same. can you help me. </p>
<p>what i need to do in for is:</p>
<p>temp = aif(I);<br />
for v = I:1<br />
   if(aif(v)&gt;temp)<br />
      temp=aif(v);<br />
      v = v-1;<br />
   else<br />
      arr = aif(v);<br />
      disp(arr);<br />
   end<br />
end<br />
how do i replace the for loop here?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-30406</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 23 Jun 2009 20:36:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-30406</guid>
		<description>Natarajan-

You have not provided enough information for me to have any insight.  I recommend you contact support (link on the right side) with more details and they will help you out.  Off-hand, for and while loops are neither worse nor better than each other - but used for different purposes typically.

The profiler, M-Lint, and the last 3 sections of the MATLAB documentation under Programming Fundamentals:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bqjgwp9.html

have a lot of advice for code optimization.

--Loren</description>
		<content:encoded><![CDATA[<p>Natarajan-</p>
<p>You have not provided enough information for me to have any insight.  I recommend you contact support (link on the right side) with more details and they will help you out.  Off-hand, for and while loops are neither worse nor better than each other &#8211; but used for different purposes typically.</p>
<p>The profiler, M-Lint, and the last 3 sections of the MATLAB documentation under Programming Fundamentals:</p>
<p><a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bqjgwp9.html" rel="nofollow">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bqjgwp9.html</a></p>
<p>have a lot of advice for code optimization.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Natarajan</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-30405</link>
		<dc:creator>Natarajan</dc:creator>
		<pubDate>Tue, 23 Jun 2009 18:26:38 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-30405</guid>
		<description>Hi Loren,

I wrote a program for processing images of size 4008 x4008.

When i executed the code,the code runs for almost 2 days.Also if i change the input data as 8-bit,i do get a result but if i give the original 16-bit data as input..an error is thrown stated as out of memory exception.(Help memory).. 

Actually i need several instances of the image and there was an inherent need to use several for loops.Could this cause a overhead.( it suggested me to consider preallocating for speed but there is a memory limitation along with the speed).


so i am wondering if while is better than for loop.? 

I would appreciate if you could give me a light on this part.It would be great if Matlab could provide few materials about code optimization in Matlab.</description>
		<content:encoded><![CDATA[<p>Hi Loren,</p>
<p>I wrote a program for processing images of size 4008 x4008.</p>
<p>When i executed the code,the code runs for almost 2 days.Also if i change the input data as 8-bit,i do get a result but if i give the original 16-bit data as input..an error is thrown stated as out of memory exception.(Help memory).. </p>
<p>Actually i need several instances of the image and there was an inherent need to use several for loops.Could this cause a overhead.( it suggested me to consider preallocating for speed but there is a memory limitation along with the speed).</p>
<p>so i am wondering if while is better than for loop.? </p>
<p>I would appreciate if you could give me a light on this part.It would be great if Matlab could provide few materials about code optimization in Matlab.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-29556</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 30 Jun 2008 10:51:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-29556</guid>
		<description>German-

What you may need to do is to set a variable in the inner loop (switch between true and false if you break).  In the outer loop, check to see if the inner loop broke or not and act accordingly.

--Loren</description>
		<content:encoded><![CDATA[<p>German-</p>
<p>What you may need to do is to set a variable in the inner loop (switch between true and false if you break).  In the outer loop, check to see if the inner loop broke or not and act accordingly.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: German</title>
		<link>http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-29555</link>
		<dc:creator>German</dc:creator>
		<pubDate>Sun, 29 Jun 2008 19:10:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/29/for-versus-while/#comment-29555</guid>
		<description>I am  doing some nested while loops, but in the inner while loop I have a for loop inside of it, then I have a condition that needs to break the while loop but since break applies to the for loop also I wonder how I do it?, do you need a sample of it?</description>
		<content:encoded><![CDATA[<p>I am  doing some nested while loops, but in the inner while loop I have a for loop inside of it, then I have a condition that needs to break the while loop but since break applies to the for loop also I wonder how I do it?, do you need a sample of it?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

