简体   繁体   中英

How to make ++ operator increments stack with shorter code?

I wanted to figure out a way to make my floating points move and change faster than the typical x++ so I decided to add more of those increments into the same while loop so they stack

While (True)
{
    x++;
    x++;
    x++;
    x++;
}

The functionality works but how do i do this with shorter code?

You can replace that with:

while (...)
{
    x += 4;
}

This represents x = x + 4

You can also do this with subtraction, multiplication, and division, respectively -= , *= , and /= . Read more here

x += 4; // Adds 4 to x, and stores the result in x.

Try += operator:

x+=4;

in this way x will be incremented by 4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM