wfbarksdale
wfbarksdale

Reputation: 7606

What is wrong with my do/while loop?

the following code gives me an error of: "expected ';' before '{' token". can anyone see why?

do {
  r = rand() % numElements;
} while ([questionsShown containsObject:r] && myCount < numElements) {
  //code here…
}

Upvotes: 0

Views: 212

Answers (2)

Anon.
Anon.

Reputation: 59973

The structure of a do/while loop is so:

do {
    //code
} while (condition);

//more code

(Note the semicolon at the end).

Your code looks like:

do {
    r = rand() % numElements;
} while ([questionsShown containsObject:r] && myCount < numElements)

{
    //code here...
}

See how you're missing a semicolon?

Upvotes: 1

thyrgle
thyrgle

Reputation:

Yes, you have two brackets after your while. Get rid of those. Plus place a semicolon.

do { 
r = rand() % numElements; 
// code should go here
} while ([questionsShown containsObject:r] && myCount < numElements);

Upvotes: 5

Related Questions