Question on increasing variables with for loop

I understand that count++ in the Bulls & Cows code would increase the variable of count by one each time the loop runs

How would I go by doing this but with different increments (2,3, etc)? I don’t need it for anything, I’m just curious.

You can have the loop increment a variable by any number with the following code:

for(int counter = 0; counter < integer; counter += integer)

As a specific example, to increment a number by 2 each loop:

for(int counter = 0; counter < 10; counter += 2)
1 Like

just to reinforce:

count++;
count += 1;
count = count + 1;

are all basically equivalent.

2 Likes

count = count +1; seems like a better way to put it IMO, thanks

Privacy & Terms