|
|
楼主

楼主 |
发表于 2010-11-12 17:26:32
|
只看该作者
跟crakman做sas base认证试题(40)
From crackman's blog on Baidu
<p><br>
<font size="4">40.The following SAS program is submitted:<br>
<br>
data WORK.PRODUCTS;<br>
Prod=1;<br>
do while(Prod LE 6); <br>
Prod + 1;<br>
end;<br>
run; <br>
<br>
What is the value of the variable Prod in the output data set?</font></p>
<p><font size="4"> A. 6 <br>
B. 7 <br>
C. 8 <br>
D. . (missing numeric) <br>
<br>
Answer: B<br>
本文属于博客:</font><a href="http://hi.baidu.com/crack_man/home"><font size="4"><!-- m --><a class="postlink" href="http://hi.baidu.com/crack_man/home">http://hi.baidu.com/crack_man/home</a><!-- m --></font></a><font size="4"> 版权归作者所有,欢迎转载!如有转载,请务必注明出处!未经本文作者同意</font></p>
<p><font size="4">不得用于商业应用。</font></p>
<p><font size="4">这道题考察的是DO WHILE语句中循环执行条件的判断时点。<br>
到底是先判断再执行还是先执行在判断?<br>
DO WHILE是先判断然后执行,也就是说PROD=1,先判断 PROD LE 6是否为TRUE,然后决定是否执行循环语句。<br>
循环每次执行完,PROD自动加1,也就是当PROD LE 6的为TRUE时,PROD最大值就是6,超过6就不执行循环内的语句,就是PROD加1了,</font></p>
<p><font size="4">但是PROD等于6的时候,依然要执行循环,LE就是小与等于的意思。所以最终PROD=7。</font></p>
<p><font size="4">如果改成:<br>
data WORK.PRODUCTS;<br>
Prod=1;<br>
do until(Prod LE 6); <br>
Prod + 1;<br>
end;<br>
run;<br>
那么PROD=2,为什么等于2?<br>
因为DO UNTIL是执行后再判断,PROD执行一次之后变成2,2 LE 6是true,所以终止执行!。UNTIL里面的表达式是循环终止的判断条件</font></p>
<p><font size="4">,如果UNTIL里面为真,那么就终止执行DO LOOP;而WHILE的表达式是循环继续的判断条件,为真继续执行DO LOOP。</font></p>
<p><font size="4">英文解释:<br>
The DO UNTIL statement executes statements in a DO loop repetitively until a condition is true, checking the </font></p>
<p><font size="4">condition after each iteration of the DO loop. The DO WHILE statement evaluates the condition at the top of the loop; </font></p>
<p><font size="4">the DO UNTIL statement evaluates the condition at the bottom of the loop. </font></p>
<p> </p>
<p> </p> <a href="http://hi.baidu.com/crack%5Fman/blog/item/5ae2f4fed9fba7ceb58f31d7.html">阅读全文</a>
<br/><b>类别:</b><a href="http://hi.baidu.com/crack%5Fman/blog/category/%B8%FAcrackman%D7%F6sas%20base%C8%CF%D6%A4%CA%D4%CC%E2">跟crackman做sas base认证试题</a> <a href="http://hi.baidu.com/crack%5Fman/blog/item/5ae2f4fed9fba7ceb58f31d7.html#comment">查看评论</a> |
|