Unit-2.1 Control Statements
Unit-2.1 Control Statements
Example
#include<stdio.h>
void main()
{
int a; F
a==10
printf(“Enter any number:”);
scanf(“%d”,&a);
if(a == 10) T
{
printf(“We are in if statement…\n”); 2 printf statements
}
else
printf… END
printf(“Condition is FALSE….”);
printf(“END”);
}
Enter any number: 10
Condition is TRUE…
END
Writing a if statement inside another if statement is called nested if
statement.
Writing a if statement inside else of an if statement is called if-else-if
statement.
What is an expression?
In any programming language, if we want to perform any calculation or
to frame any condition etc., we use a set of symbols to perform the task.
These set of symbols makes an expression.
Operands are the values on which the operators perform the task.
Here operand can be a direct value or variable or address of memory
location.
Expression Types in C
In the C programming language, expressions are divided into
THREE types. They are as follows...
1. Infix Expression
2. Postfix Expression
3. Prefix Expression
Note
3
5
1 #include<stdio.h>
void main()
{
2 int i;
for(i=1; i<=10; i++)
{
4 printf(“MRIT\n”);
3 }
printf(“End”);
5 }
IMPORTANT POINTS TO BE REMEMBER
WHILE USING FOR LOOP STATEMENT
When we use for statement, we must follow the
following...
for is a keyword so it must be used only in lower case letters.
Every for statement must be provided with initialization,
condition, and modification (They can be empty but must be
separated with ";")
Ex: for ( ; ; ) or for ( ; condition ; modification ) or for ( ;
condition ; )
In for statement, the condition may be a direct integer value, a
variable or a condition.
The for statement can be an empty statement.
In above slides we are covered about the types of control
statements
1. if
2. switch
1. Conditional 3. while
4. do - while
5. for
1. goto
2. Unconditional 2. break
3. continue
This is used to jump from one line to any other line within
the program