[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 30 KB, 460x362, christopher-hitchens-cancer.jpg [View same] [iqdb] [saucenao] [google]
2208239 No.2208239 [Reply] [Original]

Hey guys, it is possible to create multivariable loops in C? As in:

for (i = 1, j = 1; ;)

>> No.2208244

nested loops?

>> No.2208254

As long as both variables exist, that's fine. Why did you need to ask? Go fucking try it.

>> No.2208255

I can't use a nested loop. I don't have enough brackets.

>> No.2208257

>>2208239
Protip: For loop is just a shortcut for a while loop

so you could always do:

for(i=1;;)
{
-->j=1;
-->//code
}

or

i=1;
j=1;
while(condition)
{
-->//code
}

>> No.2208267

for (initializer; condition; increment) {loop body} is just a compiler macro for:

initializer;
while (condition)
{loop body;
increment;
}

>> No.2208292

It depends on the compiler. Most compilers for small device instruction sets won't let you because they go directly from that syntax to a single register DJNZ operation. Even when it can pass as legal code its still shitty structure.