106 Part II: Writing Your Own Java Programs (Simple web server)
106 Part II: Writing Your Own Java Programs Figure 5-2: An if statement is like a fork in the road. Does inputNumber equal randomNumber? ********** *You win.* ********** You lose. The random number was… Thank you for playing. yes no Sometimes, when I m writing about a condition that s being tested, I slip into using the word expression instead of condition. That s okay, because every condition is an expression. An expression is something that has a value and, sure enough, every condition has a value. The condition s value is either trueor false. (For revealing information about expressions and values like trueand false, see Chapter 4.) The double equal sign In Listing 5-1, in the ifstatement s condition, notice the use of the double equal sign. Comparing two numbers to see whether they re the same isn t the same as setting something equal to something else. That s why the symbol to compare for equality isn t the same as the symbol that s used in an assignment or an initialization. In an ifstatement s condition, you can t replace the double equal sign with a single equal sign. If you do, your program just won t work. (You almost always get an error message when you try to compile your code.) On the other hand, if you never make the mistake of using a single equal sign in a condition, you re not normal. Not long ago, while I was teaching an introductory Java course, I promised that I d swallow my laser pointer if no one made the single equal sign mistake during any of the lab sessions. This wasn t an idle promise. I knew I d never have to keep it. As it turned out, even if I had ignored the first ten times anybody made the single equal sign mistake during those lab sessions, I would still be laser-pointer free. Everybody mistakenly uses the single equal sign several times in his or her programming career. The trick is not to avoid making the mistake; the trick is to catch the mistake whenever you make it.
Would you like to be a member of headache free web site owner’s community. Now you can. We focus in IX Web Hosting, go go go!