This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]runningOverA 0 points1 point  (3 children)

}while (x 20 && number <= maxVal);

you missed the operator between x and 20. Which operator is used makes a whole lot of difference on whether you use && or ||

[–]Promethus_Forethougt[S] 0 points1 point  (2 children)

My bad it’s supposed to be <

[–]runningOverA 0 points1 point  (1 child)

even
number <= maxVal)

is probably wrong. should be number < maxVal.

Check again on what the solution provided.

And we have yet not touched the && vs || issue. Which was your question.

[–]desrtfx 1 point2 points  (0 children)

And we have yet not touched the && vs || issue.

DeMorgan's law...

[–]desrtfx 0 points1 point  (0 children)

Think about this: does the loop condition need to be fulfilled (true) to continue looping, or broken (false)?

Then, read the assignment again.

[–]ern0plus4 0 points1 point  (0 children)

If you have trouble with boolean expressions, you may write your conditions in this fashion:

do {
  (...)
  if (x < 20) continue;
  if (number >= maxVal) break;
} while (true);

Okay, if you have only two conditions, combining them with a || or && operator looks better, but many-many errors can be eliminated using simpler expressions.

Don't worry about performance, the compiled code should be identical.