我在理解 C 中的“do-while”语句时遇到问题。
这是完整的代码: http: //pastebin.com/uPRvRscd
该程序生成 6 个数字,范围从 0 到 50。这 6 个数字中没有一个数字重复。
这是 do-while 循环:
for(c=0;c<BALLS;c++)
{
/* See if a number has been allready been drawn */
do
{
ball = rand() % RANGE; /* Generate the random ball */
}
while(numbers[ball]); /* How is this compare made ? */
/* Number drawn */
numbers[ball] = 1; /* What is this for ?!? */
printf("%2d ", ball+1); /* add 1 to ball so ball won't be zero */
}
逻辑比较如何工作?
我知道 DO 取决于 WHILE 是真还是假。
numbers[ball] = 1;
这应该做什么?(如果我删除它,结果是一样的)
谢谢