6. How many times will the following code will executed?
A-5
While A>0;
Print(A)
Print("thank you")
(i) 5 times
(ii) Once
(iii) Infinite
(iv) None of these
Answers
Answered by
13
Source code:
A = 5
while a > 0:
print(A)
print("Thank you")
Output:
5
Thank you
5
Thank you
5
Thank you
.
.
.
.
infinity
Explanation:
A while loop is an iteration statement. This means that it will keep looping as long as the given while condition results to true.
We've assigned the value 5 into A.
The condition given for the while loop, was that if A was greater than 0, it had to print A and "Thank you".
Since A was greater than 0, it printed the value of A and then printed "Thank you".
Since we haven't specified if the value of A must increment, or that a break should take place, the loop will continue infinite times, because the value of A [which is 5] is always greater than 0.
Therefore, the answer is (iii) infinite.
Similar questions
Business Studies,
3 months ago
Hindi,
7 months ago
Math,
7 months ago
Hindi,
11 months ago
Math,
11 months ago