|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#3
|
||||
|
||||
|
Re: Weird problem with if statements
Quote:
if(1 == x) { } instead of if(x == 1) { } With the correct comparison syntax (as written), you should see no difference when you compile, but if you were to mistakenly put a single '=' instead of a double, you would see the a syntax error. This is because it tries to assign the value of x to 1. Since you don't have permission to write to 1, you get the error. Note that if you were to be comparing two variables, instead of a variable to a constant number, you wouldn't see the syntax error because you would be allowed to write one variable into another (in most cases). There are some people that use this as their coding standard. I personally don't use it, but it may be something that helps you get in the habit of remembering the == when comparing. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming Problem: Extremely Frustrating | chantilly_team | Programming | 19 | 12-02-2005 23:00 |
| Physics Problem | Venkatesh | Math and Science | 13 | 30-11-2004 20:30 |
| Weird Output from Dashboard Port | Ian W. | Programming | 9 | 06-03-2004 21:33 |
| The problem with scouting... | archiver | 2001 | 10 | 23-06-2002 23:49 |
| Major problem with chipphua motors | aka Scott White | Motors | 18 | 19-03-2002 19:44 |