0% found this document useful (0 votes)
17 views5 pages

Theory

In C programming, there are three main types of control statements: selection statements (like if/else), iteration statements (like for/while loops), and jump statements. Selection statements allow a program to execute different code blocks based on whether a condition is true or false. Iteration statements allow code to repeat based on conditions or a set number of times. Jump statements transfer control within a program. Common examples like if/else, for loops, and break/continue were provided.

Uploaded by

coderasylem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Theory

In C programming, there are three main types of control statements: selection statements (like if/else), iteration statements (like for/while loops), and jump statements. Selection statements allow a program to execute different code blocks based on whether a condition is true or false. Iteration statements allow code to repeat based on conditions or a set number of times. Jump statements transfer control within a program. Common examples like if/else, for loops, and break/continue were provided.

Uploaded by

coderasylem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Control statement =>

In C programming, a control statement is a statement that alters the low of execution of a


program.
There are three main types of control statements in C:
 Selection Statements (Conditional Statements)
 Iteration Statements (Loops)
 Jump Statements.
Selection Statements (Conditional Statements)=>

>>Conditional statements in C are programming constructs that allow a


program to execute different blocks of code based on whether a certain
condition is true or false. The most common types of conditional
statements in C are the if, else if, and else statements.
For example=>

**1)if (condition)

// statements to execute if condition is true

**2)

if (condition)

// statements to execute if condition is true

else

// statements to execute if condition is false

switch statement in C=>

The switch statement in C is a decision control statement that is typically


used when the user must choose between multiple alternatives.

A switch statement allows programmers to execute different blocks of


code based on the value of a single variable or expression.

For example=>
switch (expression) {
case value1:
// Code to be executed if expression == value1
break;
case value2:
// Code to be executed if expression == value2
break;
...
default:
// Code to be executed if none of the cases match
break;
}

Iteration Statements (Loops)=>

We use loops it to execute a block of code repeatedly based on a condition


or a set of conditions. We have primarily three types of iteration
statements: for loop, while loop, do-while loop.
For loop=>
The for loop in C is a programming construct that allows us to execute a
block of code repeatedly, until a specific condition is met. The syntax for a
for loop is as follows:

Syntax=>
for (initialization; condition; update) {
// code to be executed
}
while loop=>
A while loop in C is a control low structure that allows for a piece of code
to be executed repeatedly as long as a particular condition is true.

Syntax:

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

do-while loop=>
The do-while loop checks the condition after executing the loop body,
which ensures that the loop body is executed at least once, even if the
condition is initially false.

So even if a condition is false in the first place, the do-while loop


would have already run once. A do-while loop is very much similar
to a while loop, except for the fact that it is guaranteed to execute
the body at least once.

Syntax:
do {
// code block
} while (condition);
Jump statement:
Jump Statement in C is used in C programming language to
transfer control from one part of the program to another.
There are four types of Jump Statements in C: break,
continue,return and goto. While these statements can be useful in
certain situations, they can also lead to errors if not used properly.
Nested loop=>
A nested loop is a loop inside another loop. The most common nested loop
is a for loop.
For example =>

// outer loop

for (int i = 1; i <= 5; ++i) {

// codes

// inner loop

for(int j = 1; j <=2; ++j) {

// codes

**Nested loops are also called "loop inside loops"

Ladder conditions=>
if else if ladder in C programming is used to test a series of conditions sequentially.
For example =>
void main() {
int number;

printf("Enter a number: ");


scanf("%d", &number);

if (number > 0) {
printf("The number is positive.\n");
}

else if (number < 0) {


printf("The number is negative.\n");
}
else {
printf("The number is Zero\n");
}

getch();
}

You might also like