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
Math,
1 month ago
English,
1 month ago
Computer Science,
3 months ago
Hindi,
3 months ago
Computer Science,
9 months ago
Math,
9 months ago
Math,
9 months ago