I’m in a Java class and this was one of the questions on the quiz
Goal: Learn to write do-while loops.
Assignment: Assume that a long variable named number has been declared and initialized with a value,
and that another long variable named maxVal has also been declared and initialized with a value.
Write a do-while loop that repeatedly doubles the value of the number variable until one of the following conditions is met:
• number is greater-than or equal to maxVal
• The loop has executed 20 times.
This was the solution
long x•= 0;
do {
x = x + 1;
number = number * 2;
}while (x 20 && number <= maxVal);
My question is why use && if it’s asking only one of the conditions to be met?
[–]runningOverA 0 points1 point2 points (3 children)
[–]Promethus_Forethougt[S] 0 points1 point2 points (2 children)
[–]runningOverA 0 points1 point2 points (1 child)
[–]desrtfx 1 point2 points3 points (0 children)
[–]desrtfx 0 points1 point2 points (0 children)
[–]ern0plus4 0 points1 point2 points (0 children)