It's not nearly as costly as you think it is. Stop trying to microoptimize useless stuff like this at the cost of clarity. A good enough C compiler will already handle this nicely, for example, multiplication by constants is optimized by some compilers, here's one possible optimization for reg*3 on x86:
8D0440 LEA EAX,DWORD PTR DS:[EAX+EAX*2]
Which is faster than your add by 3, especially if the variable is not in a separate register.
tl;dr: Stop microoptimizing, a good compiler will take care of it.
Name:
Dinga2010-09-12 4:37
>>2
I was describing an optimizing process used by good enough compilers, not programmers.
>>9
The first is clear in that it will print the multiples of 3 from 1 to 5 from the first look at the code, while the second requires you to infer that it's generating then printing each multiple of 3 from 1 to 5. The difference is small, but the first is slightly more clear, if not by much.