CH03.FM - 127 • • • • • • • • • • •...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 127 • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • C HAPTER 3 F LOW OF C ONTROL F LOW OF C ONTROL 3.1 B RANCHING S TATEMENTS 128 The if-else- Statement 129 Introduction to Boolean Expressions 131 Gotcha Using == with Strings 135 Programming Tip Alphabetical Order 136 Nested Statements and Compound Statements 140 Java Tip Matching else ’s and if ’s 141 Multibranch if-else- Statements 143 Programming Example Assigning Letter Grades 145 The switch- statement 148 Gotcha Omitting a break- Statement 150 The Conditional Operator (Optional) 152 3.2 J AVA L OOP S TATEMENTS 154 while- Statements 155 Java Tip A while- Loop Can Perform Zero Iterations 157 The do-while- Statement 159 Programming Example Bug Infestation 161 Gotcha Infinite Loops 165 The for- Statement 167 The Comma in for- Statements (Optional ) 168 Gotcha Extra Semicolon in a Loop Statement 172 Java Tip Choosing a Loop Statement 174 The break- Statement in Loops 175 Gotcha Misuse of break- Statements 175 The exit Method 176 3.3 P ROGRAMMING WITH L OOPS 177 The Loop Body 179 Initializing Statements 180 Ending a Loop 181 Programming Tip Do Not Declare Variables in a Loop Body 183 Programming Example Nested Loops 183 Loop Bugs 186 Tracing Variables 188 3.4 T HE T YPE boolean 189 Boolean Expressions and Boolean Variables 190 Programming Tip Naming Boolean Variables 191 Precedence Rules 191 Input and Output of Boolean Values 195 Case Study Using a Boolean Variable to End a Loop 196 Chapter Summary 199 Answers to Self-Test Questions 200 Programming Exercises 204 F LOW OF C ONTROL F LOW OF C ONTROL 3 • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • F low of control is the order in which a program performs actions. Until this chap- ter, that order has been simple. Actions were taken in the order in which they were written down. In this chapter, we show you how to write programs with a more com- plicated flow of control. Java, and most other programming languages, uses two kinds of statements to produce this more complicated flow of control: A branching statement chooses one action from a list of two or more possible actions. A loop statement repeats an action again and again until some stopping condition is met.repeats an action again and again until some stopping condition is met....
View Full Document

This note was uploaded on 04/29/2010 for the course CS 5503 taught by Professor Kaylor during the Spring '10 term at University of West Alabama-Livingston.

Page1 / 82

CH03.FM - 127 • • • • • • • • • • •...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online