We need to solve question number 35. The question asks: Consider the 'while' loop and the 'repeat until' loops given below: ``` count_x = 1 while count_x <=10 count_x = count_x+2 end while count_y =1 repeat count_y = count_y+2 until count_y <=10 ``` What are the values of count_x and count_y after completion of the execution of while and repeat until loops respectively?
2025/5/6
1. Problem Description
We need to solve question number
3
5. The question asks: Consider the 'while' loop and the 'repeat until' loops given below:
```
count_x = 1
while count_x <=10
count_x = count_x+2
end while
count_y =1
repeat
count_y = count_y+2
until count_y <=10
```
What are the values of count_x and count_y after completion of the execution of while and repeat until loops respectively?
2. Solution Steps
First, let's trace the 'while' loop:
- count_x =
1. Since $1 <= 10$, the loop executes. count_x becomes $1+2=3$.
- count_x =
3. Since $3 <= 10$, the loop executes. count_x becomes $3+2=5$.
- count_x =
5. Since $5 <= 10$, the loop executes. count_x becomes $5+2=7$.
- count_x =
7. Since $7 <= 10$, the loop executes. count_x becomes $7+2=9$.
- count_x =
9. Since $9 <= 10$, the loop executes. count_x becomes $9+2=11$.
- count_x =
1
1. Since $11 <= 10$ is false, the loop terminates.
Now, let's trace the 'repeat until' loop:
- count_y =
1. The loop executes. count_y becomes $1+2 = 3$.
- count_y =
3. Since $3 <= 10$ is false, the loop executes. count_y becomes $3+2=5$.
- count_y =
5. Since $5 <= 10$ is false, the loop executes. count_y becomes $5+2=7$.
- count_y =
7. Since $7 <= 10$ is false, the loop executes. count_y becomes $7+2=9$.
- count_y =
9. Since $9 <= 10$ is false, the loop executes. count_y becomes $9+2=11$.
- count_y =
1
1. Since $11 <= 10$ is true, the loop terminates.
Therefore, the values of count_x and count_y are 11 and 11, respectively.
3. Final Answer
(4) 11 and 11