#Increment \ Decrement greater than 1 per loop

13 messages · Page 1 of 1 (latest)

empty robin
#

I'm new to coding. Is there a way to set a higher increment \ decrement of a variable other than ++x--x?
I want to remove 5 from the int variable 'x' each time the loop occurs, until x will equal 0.

primal phoenixBOT
#

This post has been reserved for your question.

Hey @empty robin! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

pearl flower
#
x+=5;
x-=5;
#

+= and -= is what you are looking for

empty robin
#

I should put that where the ‘- -x;’ is¿

pearl flower
#

by the way:
usually we would put the increment/decrement here

for(int i = 0; i < x; i+=5){
//code
}
pearl flower
#

as I said it is best practice to write the increment/decrement in its allocated place tho

#

This way other developers and yourself will not have to go looking for it 🙂

empty robin
#

I’ll implement those tips next time coding. Thank you!

primal phoenixBOT
pearl flower
#
x+=5;

is the same as

x = x + 5;