what for (i=0;1;i++)
exactly does? when the for loop
will terminate? after reaching value of i=1
? When will that happen?
(looked for this type of loop in internet and Book C(how to program, Deitel&Deitel), without any result...)
int i;
for (i=0;1;i++)
{
if (*Something Happens*)
break;
}
Since in C an int
can be interpreted as a boolean using a zero/non-zero rule (zero means "false", anything else means "true") the loop is going to continue until a break
statement is reached inside the loop's body.
You can rewrite the same loop as
for (i=0; ;i++)
because in the absence of a condition in the middle the loop is going to continue until a break
as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With