C#.NET Loop Control and Decision Control Statements
Decision Control Statements in C#
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 into 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 C# we use these Decision Making Control Structures.
Loop Control Statements in C#
The Loop Controls in C# help us to keep performing a task a certain number of times or until a certain condition becomes true.
The loop constructs available in C# are:
- while loop in C#
- do while loop in C#
- for loop in C#
- foreach loop in C#
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)