Java Tutorials - Herong's Tutorial Examples
∟Control Flow Statements
This chapter provides tutorial notes and Control Flow Statements. Topics include decision-making statements: 'if' and 'switch' statements; looping statements: 'for', 'while' and 'do' statements; branching statements: 'break', 'continue', and 'return' statements.
What Is Control Flow Statement
"if-then" Statements
"if-then-else" Statements
Nested "if-then-else" Statements
"switch" Statements
Fall-Through Behavior of "switch" Statements
Basic "for" Statements
Enhanced "for" Statements
"while" Statements
"do" Statements
"break" Statements
Labeled "break" Statements
"continue" Statements
Labeled "continue" Statements
Takeaways:
- A Control Flow Statement is a statement that
changes the default flow of execution, which run statements
one by one sequentially.
- An "if-then" statement is a decision-making statement
that executes the contained sub-statement only when
the given "boolean" expression is "true".
- An "if-then-else" statement is a decision-making statement
that executes only the first contained sub-statement when
the given "boolean" expression is "true".
Otherwise it executes only the second contained sub-statement.
- "if-then-else" statements can be nested as
"if ... else if ... else if ... ... ... else".
- A "switch" statement is a decision-making statement that executes
a portion of the contained statement block by passing control to a sub-statement based on label matching.
- A basic "for" statement is a looping statement
that executes the contained statement repeatedly
with an initial logic, a looping condition, and an update logic.
- An enhanced "for" statement is a looping statement
that executes the contained statement repeatedly
for each element in a given list.
- A "while" statement is a looping statement
that executes the contained statement repeatedly
while a given condition is true.
- A "do" statement is a looping statement
that executes the contained statement immediately, then repeat it
while a given condition is true.
- A non-labeled "break" statement is a branching statement
that transfers the control to the end of the immediate enclosing
"switch", "while", "do", or "for" statement.
- A labeled "break" statement is a branching statement
that transfers the control to the end of the labeled
enclosing block statement.
- A non-labeled "continue" statement is a branching statement
that transfers the control to the end of the immediate enclosing loop block
and continues the next iteration of the loop.
- A labeled "continue" statement is a branching statement
that transfers the control to the end of the labeled enclosing loop block
and continues the next iteration of the labeled loop.
Table of Contents
About This Book
JDK - Java Development Kit
Execution Process, Entry Point, Input and Output
Primitive Data Types and Literals
►Control Flow Statements
Bits, Bytes, Bitwise and Shift Operations
Managing Bit Strings in Byte Arrays
Reference Data Types and Variables
Enum Types and Enum Constants
StringBuffer - The String Buffer Class
System Properties and Runtime Object Methods
Generic Classes and Parameterized Types
Generic Methods and Type Inference
Lambda Expressions and Method References
Java Modules - Java Package Aggregation
Execution Threads and Multi-Threading Java Programs
ThreadGroup Class and "system" ThreadGroup Tree
Synchronization Technique and Synchronized Code Blocks
Deadlock Condition Example Programs
Garbage Collection and the gc() Method
Assert Statements and -ea" Option
Annotation Statements and Declarations
Java Related Terminologies
Archived Tutorials
References
Full Version in PDF/EPUB