m = NULL
is assignment statement, m == NULL
is the comparison statement to be used in your if
statement
Note:
Checking m
for NULL
should be done before using it for even printing (in cout
)
If you want to continue the while loop till the last element or till val equals n, then it should be like this
while(m != NULL && m->val != n)
{
cout<<"Looking for main node. Comparing"<<n<<" to "<<m->val<<endl;
m = m->next;
}