How many times is the following loop executed?
FOR N = 8 TO 3 STEP 2
PRINT N
NEXT N
Answers
Answered by
1
Answer:
When i = 0: It’s true because 0 < 4.
Hence, the loop executes 1 time.
The value of i then increments and is increased by one, hence:
Now, i = 1: This is again true because 1 < 4
Hence, loop executes 2 times.
The value of i then increments again and is increased again by 1.
So now, i = 2: This is true again because 2 < 4
Hence, the loop executes 3 times.
Now, the value of i increments,
and becomes 3.
Now, i = 3: This is true because 3 < 4
Hence, the loop executes for 4 times.
The value of i again is incremented and it changes into 4.
But when i = 4, 4 < 4 is not true.
Thus, the construct comes out of the loop.
Hence, the loop executes 4 times.
THANKS!
Explanation:
Similar questions
English,
2 months ago
Hindi,
2 months ago
Computer Science,
4 months ago
Hindi,
4 months ago
Computer Science,
10 months ago
Math,
10 months ago
Math,
10 months ago