问题 单项选择题

下列程序(请注意循环体内的LOOP和EXIT语句)的运行结果是( )。


X=8


DO WHILE .T.


X=X+1


IF X=INT(X/3)*3


X


ELSE


LOOP


ENDIF


IF X>10


EXIT


ENDIF


ENDDO

A.9 12

B.12 15

C.15 18

D.18 21

答案

参考答案:A

解析: DO WHILE-ENDDO语句的格式为:
DO WHILE<条件>
<命令序列>
ENDDO
执行该语句时,先判断DO WHILE处的循环条件是否成立,如果条件为真,则执行DO WHILE与ENDDO之间的<命令序列>(循环体)。当执行到ENDDO时,返回到DO WHILE,再次判断循环条件是否为真,以确定是否再次执行循环体。若条件为假,则结束该循环语句,执行ENDDO后面的语句。在循环语句的循环体中还可以出现两条特殊的命令:LOOP和EXIT。这两条命令会影响循环语句的正常执行流程。
①如果循环体包含LOOP命令,那么当遇到LOOP时,就结束循环体的本次执行,不再执行其后面的语句,而是转回DO WHILE处重新判断条件;②如果循环体包含EXIT命令,那么当遇到EXIT时,就结束循环语句的执行,转回执行EXIT后面的语句。
分析题干,首先将初始值8分别赋给两个变量X,然后进入循环。
执行X=X+1后,X=9,INT表示取整数,则INT(X/3)*3的结果为9,即IF的判断条件成立,所以输出X,即输入9,因为此时X=9,小于10,再次进入循环。执行X=X+1后,X=10,则INT(X/3)*3的结果为9,即IF的判断条件不成立,执行LOOP命令,不再执行后面的语句,而是转回DO WHILE处重新判断条件,重新执行循环。执行 X=X+1后,X=11,则INT(X/3)*3的结果为9,即IF的判断条件不成立,执行LOOP命令,不再执行后面的语句,而是转回DO WHILE处重新判断条件,重新执行循环。执行X=X+1后,X=12,则INT(X/3)*3的结果为12,即Ⅳ的判断条件成立,所以输入X,即输入12,因为此时X=12,大于10,执行EXIT命令,跳出循环。最后输出的是9和12。

阅读理解

The American Museum of Natural History

Address: Central Park West at 79th, St., New York
Tel: 212-769-5100
Traffic: located on the Upper West Sideof Manhattan, the museumis conveniently reached by bus, underground or car.
Parking: There is a small parking place which charges only $7.75 per day, but is often full. Parking in the neighborhood is also limited.
Museum hours: 10:00 am to 5:45 pm Sunday through Tuesday; 10:00 am to 9:00 pm Wednesday, Thursday, Friday, and Saturday.
Admission: $3.20 for grown-ups, one-fourth for children, and free on Friday and Saturday evening from 5:00 pm to 9:00 pm.
The museum is open every day of the year except Christmas and Thanksgiving.
小题1:The American Museum of Natural History is in    .
A.PhiladelphieB.Washington
C.BostonD.New York
小题2:There is a parking place outside the museum, but    .
A.people cannot park their cars there
B.it is not big enough to park all the cars
C.it will cost you $7.75 per week
D.nobody wants to park his car there
小题3:If four grown-ups and four children want to pay a visit to the museum at 3:00 pm on Saturday, they will pay    .
A.$16B.$19.2C.$25.6D.no money
小题4:You can visit the museum    .
A.at 7:00 am on Monday
B.at 8:00 pm on Tuesday
C.at 11:00 am on Sunday
D.at 10:00 pm on Friday
小题5:From the passage, we can learn that    .
A.the museum lies in the east of New York
B.the small parking place charges more than $8 a day for a car
C.one can get to the museum by car, by under-ground or by bus
D.the museum is the most popular one in America
判断题