Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
When you write a program, you type statements into a file. Without control flow statements, the interpreter executes these statements in the order they appear in the file from left to right, top to bottom. You can use control flow statements in your programs to conditionally execute statements, to repeatedly execute a block of statements, and to otherwise change the normal, sequential flow of control. For example, in the following code snippet, theif
statement conditionally executes theSystem.out.println
statement within the braces, based on the return value ofCharacter.isUpperCase(aChar)
:The Java programming language provides several control flow statements, which are listed in the following table.char c; ... if (Character.isUpperCase(aChar)) { System.out.println("The character " + aChar + " is upper case."); }
Statement Type Keyword looping while
,do-while
,for
decision making if-else
,switch-case
exception handling try-catch-finally
,throw
branching break
,continue
,label:
,return
In the sections that follow, you will see the following notation to describe the general form of a control flow statement:
Technically, the braces, { and }, are not required if the block contains only one statement. However, we recommend that you always use { and }, because the code is easier to read and it helps to prevent errors when modifying code.control flow statement details { statement(s) }
- The while and do-while Statements
- The for Statement
- The if/else Statements
- The switch Statement
- Exception Handling Statements
- Branching Statements
- Summary of Control Flow Statements
- Questions and Exercises: Control Flow
Note : Althoughgoto
is a reserved word, currently the Java programming language does not support thegoto
statement.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.