Control instructions in C

In C, control instructions are used to control the flow of execution of a program. They allow the program to make decisions based on certain conditions, and to repeat a set of statements a certain number of times. There are three main types of control instructions in C: decision making statements, loop statements, and jump statements.

Decision making statements

Decision making statements are used to make decisions based on certain conditions. There are two types of decision making statements in C:

if statement: The if statement is used to execute a set of statements if a certain condition is true. The syntax of the if statement is as follows:

if (condition) {
    // statements to be executed if condition is true
}

if-else statement: The if-else statement is used to execute a set of statements if a certain condition is true, and a different set of statements if the condition is false. The syntax of the if-else statement is as follows:

if (condition) {
    // statements to be executed if condition is true
} else {
    // statements to be executed if condition is false
}

Loop statements

Loop statements are used to repeat a set of statements a certain number of times. There are three types of loop statements in C:

for loop: The for loop is used to execute a set of statements a certain number of times. The syntax of the for loop is as follows:

for (initialization; condition; increment/decrement) {
    // statements to be executed
}

while loop: The while loop is used to execute a set of statements as long as a certain condition is true. The syntax of the while loop is as follows:

while (condition) {
    // statements to be executed
}

do-while loop: The do-while loop is used to execute a set of statements at least once, and then continue executing them as long as a certain condition is true. The syntax of the do-while loop is as follows:

do {
    // statements to be executed
} while (condition);

Jump statements

Jump statements are used to transfer control of a program to a different part of the program. There are three types of jump statements in C:

break statement: The break statement is used to terminate a loop or switch statement. When a break statement is encountered, the program jumps to the end of the loop or switch statement. The syntax of the break statement is as follows:

break;

continue statement: The continue statement is used to skip the rest of the statements in a loop and continue with the next iteration of the loop. The syntax of the continue statement is as follows:

continue;

goto statement: The goto statement is used to transfer control of a program to a different part of the program. The syntax of the goto statement is as follows:

goto label;
...
...
label: // statement to be executed

In conclusion, control instructions are an essential part of C programming, allowing the program to make decisions based on certain conditions, repeat a set of statements a certain number of times, and transfer control of the program to a different part of the program.