Re: If statement trouble
In article <iZednQvBrNDbgFnanZ2dnUVZ_oqhnZ2d@comcast.com>,
Jerry Stuckle <jstucklex@attglobal.net> wrote:
> AceX wrote:
> > On Feb 25, 5:21 pm, Tony <nos...@example.com> wrote:
> >> AceX wrote:
> >>> I'm having trouble with this if statement:
> >>> if($line[$c]=$ignore
> >>> {
> >>> $num--;
> >>> }
> >>> $ignore is defined as the string "ig"
> >>> $line is an array containing 5 items, some of which may be "ig"
> >>> $num starts out as a number representing the number of values in $line
> >> In addition to using an assignment operator (=) instead of comparison
> >> (==), you are also missing a close parenthesis:
> >> if($line[$c]=$ignore
> >> should be
> >> if($line[$c]==$ignore)
> >>
> >> And, yes, the brackets are not NEEDED if you have only one statement,
> >> but they don't hurt.
> >
> > Thank you all. I don't know if anyone else has this problem, but
> > sometimes I just have brain lapses. I appreciate all the help guys
> > (and gals?)
> >
>
> Ace,
>
> I don't know how many times I've done that - stretching all the way back
> to the mid 80's when I was writing C code :-)
>
> Also C++, Java, PHP...
>
> It's also a common error in many of my classes - students will look and
> look at the code and don't see what the problem is. When I point it out
> in about 2 seconds, they feel embarrassed - until I tell them I spotted
> it so quickly just because I HAVE made that mistake so many times. :-)
It's not only that. A certain blindness creeps in and one can overlook a
mistake a number of times even though you know there's one there. That's
when it's often much quicker to have a*fresh* set of eyes looking.
|