To better understand what I'm working on can someone please explain the condition for this for loop?Code:for( NODE * p = A.front; p; p = p->next )
To better understand what I'm working on can someone please explain the condition for this for loop?Code:for( NODE * p = A.front; p; p = p->next )
Just break the for loop into a while and everything will become more clear.
I guess you probably are running through a simple linked list. From my point of view, while loops are more appropriate in this case, because you do not really know the number that you want your loop to be executed.Code:Node* p = A.front; // I guess, that member front is of type Node* while(p) // which is equivalent to while(p != 0), which is equivalent to while(p != NULL) { //body of the for loop p = p->next; //last part of for loop }
Code - functions and small libraries I use
It’s 2014 and I still use printf() for debugging.
"Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson
The condition is equivalent to p != NULL.
The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss