Chapter 6

Making Decisions in Code

What you will learn in this chapter:

  • Relational operators
  • Comparing value types
  • Comparing reference types
  • The if and else keywords
  • Cascading if statements
  • Logical operators
  • The switch, case, break, and default keywords
  • Data validation

wrox.com code downloads for this chapter

You can find the wrox.com code downloads for this chapter at www.wrox.com/remtitle.cgi?isbn=9781118336922 on the Download Code tab. The code in the Chapter06 folder is individually named according to the names throughout the chapter.

If computers could not use data to make decisions, they would be little more than expensive boat anchors. Because it is hard to write a nontrivial program without some form of decision-making ability in it, some decision-making keywords were used in previous programs. However, what those keywords actually do was never explained. That changes by the end of this chapter.

This chapter also presents some thoughts on coding style. Coding style simply refers to the way you write program code. There are a myriad of coding styles. Because C# is not form-specific, you are free to use just about any coding style you wish. I have known brilliant programmers whose code is almost impossible to read or decipher. On the other hand, I've had mediocre students who write code that is a joy to read. True, beauty is in the eye of the beholder. However, experience has taught me that 80 percent of a program's development time is spent in testing, debugging, and maintaining ...

Get Beginning Object-Oriented Programming with C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.