Difference between revisions of "Test for equality"
Jump to navigation
Jump to search
(Created page with 'A '''test for equality''' in computer programming is one of the trickiest tests used to control a computer program. The usual syntax is something like: IF (''test'') THEN ......') |
DavidB4-bot (talk | contribs) m (→top: clean up) |
||
| Line 20: | Line 20: | ||
The curly brace languages all require a [[double equal sign]] to be used for tests. This may look strange to the beginner, but it distinguishes an [[assignment]] from a [[test]]. If you use a [[single equal sign]] your code may still compile and run, but your results will probably be incorrect. | The curly brace languages all require a [[double equal sign]] to be used for tests. This may look strange to the beginner, but it distinguishes an [[assignment]] from a [[test]]. If you use a [[single equal sign]] your code may still compile and run, but your results will probably be incorrect. | ||
| − | [[ | + | [[Category:Computer Programming]] |
Latest revision as of 15:05, June 23, 2016
A test for equality in computer programming is one of the trickiest tests used to control a computer program. The usual syntax is something like:
IF (test) THEN ... do something ELSE ... do something else END IF
or in the curly brace languages like Java, C (etc.) or PHP:
if (test) {
... do something
}
else {
... do something else
}
The tricky part is the test syntax. You can simply write x > 4 with no problem (see test for inequality), but if you check for x = 4 you could have a disastrous side effect.
The curly brace languages all require a double equal sign to be used for tests. This may look strange to the beginner, but it distinguishes an assignment from a test. If you use a single equal sign your code may still compile and run, but your results will probably be incorrect.