Introduction
Lesson 1 of 11 in Coddy's Control Statements in Java course.
Java executes programs from top to bottom.
Code is executed according to the order in which it is written.
For example, if you want to have tea or coffee in the morning, that is a decision you make. Similarly, to make some decisions in the code, you need to use Control Flow Statements.
Types:
- Decision Making Statements (if statements, switch case)
- Java decision-making statements allow you to make a decision based on the result of a condition.
- Example: Suppose you have a daily routine for work at the office, but due to some scenario you need to focus on another urgent task rather than regular work, so there is a situation that requires a change of action.
- In Java, all the code is executed sequentially, but there may arise some situations where the coder has to change the order of execution of code based on certain conditions that involve making decisions.
- Loop Statements (do while, for, while, foreach loop)
- A computer is the best example of something that can perform repetitive tasks tens of thousands of times.
- Every programming language has this feature.
- The process of repeatedly performing the same task is called looping.
- Imagine if I told you to write Hello 100 times. You would have to write 100 lines of code, but using a loop, you could do it very easily. We will see in the lessons ahead.
- Jump statements (break, continue)
- For example, if someone in your house has a cold, you may initially decide to give home remedies and try to cure it continuously, but if it is not cured, you may decide to break the decision and go to the doctor.
- In Java, jump statements are used to transfer control of the program to the specific statements.
Try it yourself
This lesson doesn't include a code challenge.
All lessons in Control Statements in Java
1What are Control Statements?
Introduction2Decision Making Statments
Simple if Statementif-else Statementif-else-if StatementNested if-StatementSwitch Case Statement