# Thread: Help with a do...while array

1. ## Help with a do...while array

I started working my way through "C All-In-One Desk Reference For Dummies" by Dan Gookin. I've made it to page 240 and got stuck on a do...while statement. The program generates 6 lotto numbers and disregards any duplicates. The snip-it of code I'm stuck on is:

Code:
```do
{
ball = random() % RANGE;
}
while(numbers[ball];```
This segment of the code is apparently checking to make sure the random number generated hasn't already been added to the array but I cannot figure out what calculation/check while(numbers[ball]) is performing to spin the loop. There is no operator present. Any help would be appreciated.

Here is the full code:

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define RANGE 50
#define BALLS 6

int main()
{
int numbers[RANGE]; // 0 to 49
int c,ball;

puts("L O T T O   P I C K E R\n");

srandom((unsigned)time(NULL));

/* initialize the array */

for(c=0;c<RANGE;c++) // if c < 50
numbers[c]=0;

printf("Press Enter to pick this week's numbers:");
getchar();

/* draw the numbers */
puts("Here they come:");
for(c=0;c<BALLS;c++)
{

/* see if a number has already been drawn */
do
{
ball = random() % RANGE;
}
while(numbers[ball]);

/* Number drawn */
numbers[ball] = 1;
printf(" %i ",ball+1);
}

printf("\n\nGood luck in the drawing!\n");
return(0);
}```

2. What do you think this line is doing?

Code:
`numbers[ball] = 1;`
It is recording that the number that matches the value of ball has been picked. The while checks to verify the number has not yet been picked.

Tim S.

3. what calculation/check while(numbers[ball]) is performing
Code:
```#include <stdio.h>

int value = 0 ;

void printValue() {
if (value) printf( "TRUE" );
if (!value) printf( "FALSE" );
printf( "\n" );
}

int main( int argc, char *argv[] ) {

value = 0; printValue();
value = 1; printValue();
value = 10; printValue();
value = -10; printValue();
value = 0; printValue();
value = 1; printValue();

return 0;
}```
Code:
```FALSE
TRUE
TRUE
TRUE
FALSE
TRUE```

4. > There is no operator present.
But in the context of an expression requiring a boolean expression,
while(numbers[ball])
is the same as
while(numbers[ball] != 0)

Since you then go onto do numbers[ball] = 1, the next time you enter that loop, if you pick the same ball again, the while loop will do it's thing.

5. Thank you, everyone! It makes sense now.