alicedimarco
alicedimarco

Reputation: 325

How to make a loop do the same thing again?

Basically, I want the if and else statements at the bottom to happen again when my counter reaches 13. How do I do it? My code is below.

int counter = 2;
int start = 19;
int end = 95;

while(!(input>=start && input<=end) /*range*/ && counter<100){

               start+=95;
               end+=95;

                   if(counter % 4 == 0)
                       end+=19;
                   else if(counter % 5 == 0)
                    start+=19;

               counter++;
        }

EDIT: Sorry for being unclear. Uhh, what I want to do is, if the if-else statements have already been executed 13 times, I want the whole thing, including the

start+=95;
end+=95;

to execute again.

Upvotes: 0

Views: 215

Answers (2)

phatfingers
phatfingers

Reputation: 10250

int innerLoop=(counter==13)?2:1;
for (int i=0; i<innerLoop; i++) {
... 
}

Upvotes: 0

c&#39;quet
c&#39;quet

Reputation: 345

wrap the codes in the loop into a method. when executes every 13 times, invoke the method again

Upvotes: 1

Related Questions