In C, control statements are used to control the flow of program execution based on certain conditions or loops. These statements allow you to make decisions and repeat actions in your code.Here are some of the key control statements in C:
1.Conditional Statements:
if (condition) {
// Code to be executed if the condition is true
}
if (condition) {
// Code to be executed if the condition is true
} else {
// Code to be executed if the condition is false
}
if (condition1) {
// Code to be executed if condition1 is true
} else if (condition2) {
// Code to be executed if condition2 is true
} else {
// Code to be executed if no condition is true
}
switch (expression) {
case constant1:
// Code to be executed if expression equals constant1
break;
case constant2:
// Code to be executed if expression equals constant2
break;
// More cases...
default:
// Code to be executed if expression doesn't match any case
}
3.Looping Statements:
for (initialization; condition; increment/decrement) {
// Code to be executed in each iteration
}
while (condition) {
// Code to be executed while the condition is true
}
do {
// Code to be executed at least once
} while (condition);