<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Do While vs Do Until in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-While-vs-Do-Until/m-p/694350#M211753</link>
    <description>&lt;P&gt;The general understanding is that a DO WHILE statement evaluates the condition at the top of the loop while a DO UNTIL evaluates the condition at the bottom of the loop.&amp;nbsp; And this holds true in an ordinary DO WHILE/DO UNTIL statement and can be demonstrated by using output statements which show that in a DO WHILE, the index "i" is not incremented beyond the upper limit of the do loop. Whereas, in a DO UNTIL, the index will be incremented by one value beyond the limit of the do loop.&lt;BR /&gt;&lt;BR /&gt;Question: How come the converse seems to be the case in the examples below i.e. the index "i" in the DO WHILE statement is incremented to 6 whereas, it stops at 5 in the DO UNTIL? Thx&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;**** How many iterations will this loop execute before terminating ****;&lt;BR /&gt;data dowhile;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 10 while(x le 4);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x + 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="oaotitoju_0-1603742554026.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51069i8CD98009824369EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="oaotitoju_0-1603742554026.png" alt="oaotitoju_0-1603742554026.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dountil;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 10 until(y gt 4);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y + 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="oaotitoju_1-1603742595109.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51070i2B07810B60B4F6C0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="oaotitoju_1-1603742595109.png" alt="oaotitoju_1-1603742595109.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Oct 2020 20:54:13 GMT</pubDate>
    <dc:creator>oaotitoju</dc:creator>
    <dc:date>2020-10-26T20:54:13Z</dc:date>
    <item>
      <title>Do While vs Do Until</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-vs-Do-Until/m-p/694350#M211753</link>
      <description>&lt;P&gt;The general understanding is that a DO WHILE statement evaluates the condition at the top of the loop while a DO UNTIL evaluates the condition at the bottom of the loop.&amp;nbsp; And this holds true in an ordinary DO WHILE/DO UNTIL statement and can be demonstrated by using output statements which show that in a DO WHILE, the index "i" is not incremented beyond the upper limit of the do loop. Whereas, in a DO UNTIL, the index will be incremented by one value beyond the limit of the do loop.&lt;BR /&gt;&lt;BR /&gt;Question: How come the converse seems to be the case in the examples below i.e. the index "i" in the DO WHILE statement is incremented to 6 whereas, it stops at 5 in the DO UNTIL? Thx&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;**** How many iterations will this loop execute before terminating ****;&lt;BR /&gt;data dowhile;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 10 while(x le 4);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x + 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="oaotitoju_0-1603742554026.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51069i8CD98009824369EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="oaotitoju_0-1603742554026.png" alt="oaotitoju_0-1603742554026.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dountil;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 10 until(y gt 4);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y + 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="oaotitoju_1-1603742595109.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51070i2B07810B60B4F6C0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="oaotitoju_1-1603742595109.png" alt="oaotitoju_1-1603742595109.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 20:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-vs-Do-Until/m-p/694350#M211753</guid>
      <dc:creator>oaotitoju</dc:creator>
      <dc:date>2020-10-26T20:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Do While vs Do Until</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-vs-Do-Until/m-p/694372#M211757</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/354216"&gt;@oaotitoju&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/354216"&gt;@oaotitoju&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;(...) And this holds true in an ordinary DO WHILE/DO UNTIL statement and can be demonstrated by using output statements which show that in a DO WHILE, the index "i" is not incremented beyond the upper limit of the do loop. Whereas, in a DO UNTIL, the index will be incremented by one value beyond the limit of the do loop.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A "pure" DO-WHILE or DO-UNTIL loop does not have an index variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your examples, however, use an &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p1cydk5fq0u4bfn1xfbjt7w1c7lu.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;&lt;EM&gt;iterative&lt;/EM&gt; DO statement&lt;/A&gt;&amp;nbsp;together with&amp;nbsp;a WHILE or UNTIL condition. The WHILE condition is indeed checked at the top of the loop, but only &lt;EM&gt;after&lt;/EM&gt; the incrementation of the index variable (i.e. the execution of the first part of the iterative DO statement). This is why variable &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt; is incremented to 6 before the check of the WHILE condition (resulting in FALSE) ends the DO loop. In the corresponding situation with the UNTIL condition the loop is left immediately (after the FALSE result has been determined at the bottom of the loop) so that no further incrementation of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt; occurs.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 21:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-vs-Do-Until/m-p/694372#M211757</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-26T21:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Do While vs Do Until</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-vs-Do-Until/m-p/694448#M211785</link>
      <description>&lt;P&gt;Thanks so much for your reply.&amp;nbsp; This does confirm my suspicion but, I just couldn't find documentation to confirm it.&amp;nbsp; Thanks once again.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 08:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-vs-Do-Until/m-p/694448#M211785</guid>
      <dc:creator>oaotitoju</dc:creator>
      <dc:date>2020-10-27T08:41:38Z</dc:date>
    </item>
  </channel>
</rss>

