I encountered a for loop where the condition is the parameter (p) itself. When will the loop stop? I don’t see this case in my C++ books.
for (PDFS *p = e->prev ; p ; p = p->prev) {
push_back (p->edge);
edge[p->edge->id] = vertex[p->edge->from] = vertex[p->edge->to] = 1;
}
The loop will stop when
pisNULL. In the loop, you don’t need to explicitly check for the conditionp !=NULL, or in C++11,p != nullptr.The similar code is also written you’ve null-terminated c-string:
In this case, you don’t need to check for the condition
i < strlen(str)or something like that.