How many times is the loop block entered when the following code executes?fоr(int i=16; і < 28; i+=2) { <code inside loop block>}
Question
How many times is the loop block entered when the following code executes?fоr(int i=16; і < 28; i+=2) { <code inside loop block>}
Solution
The loop starts at 16 and ends before 28, increasing by 2 each time.
Here are the steps:
- i = 16, 16 < 28, so enter the loop. (1st time)
- i = 18, 18 < 28, so enter the loop. (2nd time)
- i = 20, 20 < 28, so enter the loop. (3rd time)
- i = 22, 22 < 28, so enter the loop. (4th time)
- i = 24, 24 < 28, so enter the loop. (5th time)
- i = 26, 26 < 28, so enter the loop. (6th time)
- i = 28, 28 is not less than 28, so the loop ends.
So, the loop block is entered 6 times.
Similar Questions
How many times is the body of the loop executed in the code above?
___________________loops through a block of code a specified number of times0.5 Marksfor loopforeach loopBoth A and Cwhile loop
___________________loops through a block of code a specified number of times0.5 Marksforeach loopBoth A and Cfor loopwhile loop
How many times following loop will be executed?void main(){ int i = 32766; while (i<= 32767) { printf("%d\n",i); i = i + 1; }}a.2 timesb.1 timesc.infinite timesd.loop will not be executed
How many times will the following loop runfor(c = 1; c < 20; c=c+5) {document.write("C : " + c );document.write("<br />");
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.