while(true)
{
if (p == NULL)
break;
if (p->val == v)
break;
p = p->next;
}
Some explanation: the original code relies on short-circuit evaluation. p->val != v
isn't evaluated if p!=NULL
evaluates to false. If it would always evaluate the second expression, this might lead to an access violation. If you don't hva a short-circuiting &&
operator, you need to make sure in your code, p->val
is only evaluated if p!=NULL
.