Home > Software design >  what is the termination condition for this C for loop
what is the termination condition for this C for loop

Time:05-02

i found the linked code and found this for loop which is a bit strange for me. i would appreciate if someone could explain me the syntax of this loop to me. MFG

void patch(Ptrlist *l, State *s)
{
    Ptrlist *next;
    
    for(; l; l=next){
        next = l->next;
        l->s = s;
    }
}

CodePudding user response:

This for loop

for(; l; l=next){

is equivalent to

for(; l != NULL; l=next){

or

for(; l != 0; l=next){

That is the for loop is executed until the controlling expression is equal to 0.

  • Related