Create your own example of 3 specific for loop bodies Assume

Create your own example of 3 specific for loop bodies. Assume the loop counter variable - that you make up the name for (do not use i, x, a, etc.) - was declared elsewhere in the code. You do not have to write the body of the for loop. I only want to see the correct for loop body.

A. Create a for loop body that starts a loop counter from a number greater than 0 (make up a number) and continues up to and including a number that is 15 greater than the start. So if you choose to start the loop at 10, the end value inclusive would be 10 + 15 which is 25.

B. Create a for loop body that starts at some made up number greater than 50 and ends at 0 inclusive.

C. Create a for loop body that starts at 0 and ends without enter the loop at some made up number greater than the start but I want you to increase by 4.

Solution

loop1:

for(int k=start;k<=15+start;k++)
    or
    for(int k=10;k<=15+10;k++)

Here, loop starts at 10,runs till 10+15 which is 25 by icnrementing by 1 though eeach iteration

loop2:

for(int k=56;k>=0;k--)

Here, k starts at 56(value greater than 0) and runs till value is 0 by decremnting by 1 each time

loop3:

for(int k=0;k<10;k+=4)

so,here the loop starts at 0 and ends when the value is 10 but doesn\'t enter the loop and each item k is incremnted by 4

Create your own example of 3 specific for loop bodies. Assume the loop counter variable - that you make up the name for (do not use i, x, a, etc.) - was declare

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site