What will be the output of the following code?
i <- 5;
while(i > 0) {
print(i);
i <- i - 1
}
a) 5 4 3 2 1
b) 1 2 3 4 5
c) 1 2 3 4 5 0
d) Error
Answer:
a) 5 4 3 2 1
Explanation:
The while loop starts with i = 5 and decrements i by 1 in each iteration, printing the values 5, 4, 3, 2, and 1.