Java 101: Deciding and iterating with Java statements

See the original posting on JavaWorld

Java applications evaluate expressions in the context of
statements, which are standalone islands of code that accomplish
various tasks such as declaring a variable, making a decision, or iterating
over statements. A statement can be expressed as a simple statement or as a
compound statement:

  • A simple statement is a single standalone instruction
    for performing a task; it must be terminated with a semicolon character
  • A compound statement is a sequence of simple and other
    compound statements located between open- and close-brace characters
    ({ and }), which delimit the compound statement’s
    boundaries. Compound statements can be empty, will appear wherever simple
    statements appear, and are alternatively known as blocks. A
    compound statement is not terminated with a semicolon.

In this article I introduce you to using statements in your Java
programs. You can use statements to to declare variables and specify
expressions, make decisions, iterate over statements (yes, you can use
statements to iterate over statements), break and continue iteration, and do
nothing. I’ll leave some of the more exotic statements (such as statements
for returning values from called methods and for throwing exceptions) for
a future Java 101 article.

To read this article in full or to leave a comment, please click here