Is it possible to do multiple operations in increment part of for loop in C/C++?

Luka Tiger picture Luka Tiger · Oct 8, 2013 · Viewed 12.8k times · Source

Is it possible to do multiple operations in increment part of for loop in C/C++? Something like this:

int a = 0, b = 0, c = 5;
for(; a < c; increase a by 1 and increase b by 2)

Answer

0x499602D2 picture 0x499602D2 · Oct 8, 2013

Use the comma operator:

for (; a < c; ++a, b += 2)