Selection Statements


Introduction

Program control-flow statements are an important part of the Java programming language because they allow you to alter the course of program execution while the program is running. The program control-flow statements presented in this chapter fall into two categories: 1) selection statements, and 2) iteration statements.

Selection statements allow you to alter the course of program execution flow based on the result of a conditional expression evaluation. There are three types of selection statements: if, if/else, and switch.

Iteration statements provide a mechanism for repeating one or more program statements based on the result of a conditional expression evaluation. There are three types of iteration statements: for, while, and do. Java version 5 introduced the for/each statement for use with arrays and collections. I will therefore postpone coverage of the for/each statement until chapter 17.

As you will soon learn, each type of control-flow statement has a unique personality. After reading this chapter you will be able to select and apply the appropriate control-flow statement for the particular type of processing you require, enabling you to write increasingly powerful programs.

In addition to selection and iteration statements I will show you how to use the keywords break and continue. The proper use of these keywords combined with selection and iteration statements provides a greater level of processing control.

The material you learn in this chapter will fill your Java programming tool bag with lots of powerful tools. You will be pleasantly surprised at what you can program with the aid of program control-flow statements.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net