Hi friends, I have to answer this question. I think the loop will get executed infinite number of times. Am I right? or is there an trick in this question? Q) how many times the body of loop will be executed? X= 5; y=50; while (X<=y) { X = y /X …………. }
The loop will be executed an infinite number of times indeed. The value of x alters between 5 and 10 each time.
x is less than y at start and x is event getting smaller with the division. So the condition in "while" will be maintained true for any number of x = x/y executions. Since there isn't any operation on y, this loop will run indefinitely. Just added some ideas to find the answer to such questions.