Multiple Counter Problem In For Loop

后端 未结 7 1145
余生分开走
余生分开走 2020-12-16 10:59

Why is this not valid

for( int i = 0, int x = 0; some condition; ++i, ++x )

and this is

int i, x;
for( i = 0, x = 0; some c         


        
7条回答
  •  醉酒成梦
    2020-12-16 11:32

    when you need to declare two variables of different types, it can't be done by one declaration

    Hackety hack hack:

    for (struct {int i; char c;} loop = {0, 'a'}; loop.i < 26; ++loop.i, ++loop.c)
    {
        std::cout << loop.c << '\n';
    }
    

    ;-)

提交回复
热议问题