<?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 Re: Do until  and Do while can give the same results ...please check below confusing that both are t in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965346#M375830</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part of the title of your post says "confusing that both are true". By "true" do you mean "equal"? Do you think they should be different? If yes, what do you think the difference should be and why? Basically, what is the confusion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might already be aware, but in case you are not, the &lt;FONT face="courier new,courier"&gt;do until&lt;/FONT&gt; condition is only checked to see if the loop should be repeated&amp;nbsp;&lt;EM&gt;after&lt;/EM&gt; the code in the loop is executed. Whereas the &lt;FONT face="courier new,courier"&gt;do while&lt;/FONT&gt; condition is checked &lt;EM&gt;before&lt;/EM&gt; the code in the loop to see if any looping is required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you tried running the code as advised by others and still cannot understand your results, then try using a debugger if you have one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Apr 2025 09:19:27 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2025-04-29T09:19:27Z</dc:date>
    <item>
      <title>Do until  and Do while can give the same results ...please check below confusing that both are true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965286#M375819</link>
      <description>&lt;P&gt;True or False:&amp;nbsp; These two programs generate the same result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.invest;
    capital=100000;
    do until(Capital gt 500000);
        Year+1;
        capital+(capital*.10);
    end;
run;

data work.invest;
    capital=100000;
    do while(Capital le 500000);
        Year+1;
        capital+(capital*.10);
    end;
run;

&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;TABLE role="presentation" border="0" width="113px"&gt;
&lt;TBODY&gt;
&lt;TR valign="top"&gt;
&lt;TD width="40px"&gt;&lt;INPUT id="q9a" name="ques9" type="radio" value="a" /&gt;&lt;/TD&gt;
&lt;TD width="72.6px"&gt;&lt;LABEL for="q9a"&gt;&amp;nbsp;&lt;EM&gt;a.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;True&lt;/LABEL&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top"&gt;
&lt;TD width="40px"&gt;&lt;INPUT id="q9b" name="ques9" type="radio" value="b" /&gt;&lt;/TD&gt;
&lt;TD width="72.6px"&gt;&lt;LABEL for="q9b"&gt;&amp;nbsp;&lt;EM&gt;b.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;False&lt;/LABEL&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 28 Apr 2025 17:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965286#M375819</guid>
      <dc:creator>hmlong25</dc:creator>
      <dc:date>2025-04-28T17:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: Do until  and Do while can give the same results ...please check below confusing that both are t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965289#M375820</link>
      <description>&lt;P&gt;You can run the two programs and compare the results. You don't need us to work on this.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Apr 2025 18:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965289#M375820</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-28T18:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Do until  and Do while can give the same results ...please check below confusing that both are t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965294#M375824</link>
      <description>&lt;P data-unlink="true"&gt;Exactly! Perfect use case for &lt;STRONG&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068/show-comments/false" target="_self"&gt;Maxim 4:&lt;/A&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;EM&gt;"If in doubt, do a test run and look at the results. If puzzled, inquire further."&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Apr 2025 19:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965294#M375824</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-28T19:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Do until  and Do while can give the same results ...please check below confusing that both are t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965346#M375830</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part of the title of your post says "confusing that both are true". By "true" do you mean "equal"? Do you think they should be different? If yes, what do you think the difference should be and why? Basically, what is the confusion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might already be aware, but in case you are not, the &lt;FONT face="courier new,courier"&gt;do until&lt;/FONT&gt; condition is only checked to see if the loop should be repeated&amp;nbsp;&lt;EM&gt;after&lt;/EM&gt; the code in the loop is executed. Whereas the &lt;FONT face="courier new,courier"&gt;do while&lt;/FONT&gt; condition is checked &lt;EM&gt;before&lt;/EM&gt; the code in the loop to see if any looping is required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you tried running the code as advised by others and still cannot understand your results, then try using a debugger if you have one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 09:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965346#M375830</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2025-04-29T09:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Do until  and Do while can give the same results ...please check below confusing that both are t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965359#M375832</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If you run both programs, as suggested, you'll see that the results of both programs are the same whether you use a WHILE or an UNTIL: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1745933057391.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106609iCBBDE7E1DABDB727/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1745933057391.png" alt="Cynthia_sas_0-1745933057391.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; However, look at the condition that was needed to make each DO loop work to produce the same results. The UNTIL code uses (Capital &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;GT&lt;/STRONG&gt; &lt;/FONT&gt;500000) The UNTIL will ALWAYS have the loop executed at least once because the condition is checked at the bottom of the DO loop, after the statements have executed at least one time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The condition for the WHILE was (Capital &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;LE&lt;/STRONG&gt; &lt;/FONT&gt;500000) and the condition for a WHILE is checked at the top of the loop. So in this example, both loops would run the same number of times to produce the same results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If you have data and some logic that needs to be executed at least one time if the initial condition is met, then use a DO UNTIL. If you have some logic that you do NOT want to execute if the initial condition is met, then use a DO WHILE. This first example shows that both forms of the DO loop are capable of producing the same results, given that you have coded the condition correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; However, to prove that it is possible for the 2 loops to produce different results, what if in the example program, we started the value for Capital at exactly 500000 and what if we changed the logical operator in the condition for the WHILE -- so that instead of testing for LE, we just tested for LT -- then the results WOULD be different:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1745934018583.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106610i8A02C274D9F6BE5F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1745934018583.png" alt="Cynthia_sas_1-1745934018583.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Now you see that the program with DO UNTIL produced different results than the program with DO WHILE. This is not always the case, as the first program proves. You are in control of the operators used for the DO loop conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The important things to learn about DO UNTIL/DO WHILE are:&amp;nbsp; where does the condition for the loop get tested? Then, for the data and problem you are working with, do you need for the statements to execute at least one time or not? Finally, what logical operator do you need to use to make your loop work with your data? In the first program, we wanted to illustrate how it was possible for both forms of the DO loop to produce the same results. The key to making that happen was the logical operator we used in the code for the question. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; Hope this helps explain things a bit more.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 13:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965359#M375832</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2025-04-29T13:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Do until  and Do while can give the same results ...please check below confusing that both are t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965360#M375833</link>
      <description>Yes makes sense now.  Thank you!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Apr 2025 14:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965360#M375833</guid>
      <dc:creator>hmlong25</dc:creator>
      <dc:date>2025-04-29T14:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Do until  and Do while can give the same results ...please check below confusing that both are t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965369#M375837</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Finally, what logical operator do you need to use to make your loop work with your data? In the first program, we wanted to illustrate how it was possible for both forms of the DO loop to produce the same results. The key to making that happen was the logical operator we used in the code for the question.&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you want the two loops to be similar the key is that the logical expression used in the WHILE() and UNTIL() return opposite results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to preform the same test as used by the loop DO WHILE(A) you need to have use DO UNTIL(NOT A).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example code the conditions (Capital gt 500000) and (Capital le 500000) meet this criteria.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 16:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965369#M375837</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-29T16:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Do until  and Do while can give the same results ...please check below confusing that both are t</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965376#M375838</link>
      <description>Best to you!  That clarifys my future use of Do Until and While in programming!  Yay!</description>
      <pubDate>Tue, 29 Apr 2025 19:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-until-and-Do-while-can-give-the-same-results-please-check/m-p/965376#M375838</guid>
      <dc:creator>hmlong25</dc:creator>
      <dc:date>2025-04-29T19:03:42Z</dc:date>
    </item>
  </channel>
</rss>

