Java Loop Control and Decision Control Statements
Decision Control Statements in Java:
The Decision Control Structures help you to perform actions based on a certain condition.
- if else
- Nested if
- if-else-if Ladder
Let me explain this with 2 real world examples:
1. If I feel Thirsty I drink water(or beer!) else I eat pizza!
2. Consider a situation where you get in to a fight with someone in college.
Here is the decision making your mind does:
if ( The other person is weaker than me)
Beat the shit out of him!
Keep Quiet and move on !!
We face such situations every day in our life where we have to take decisions based on a condition. To implement such situations in Java we use these Decision Making Control Structures.
Loop Control Statements:
The Loop Controls in Java helps us to keep performing a task a certain number of times or until a certain condition becomes true.
The loop constructs available in Java are:
- while loop in java
- do while loop in java
- for loop in java
- for each loop in java
Example: Suppose, you are playing football,
You keep playing football until you feel tired. (while, Do while)
You keep playing football for 45 minutes continuously i.e. till half-time break (Similar to :for loop)