Professional Documents
Culture Documents
Fop 1.3 (22MSM40017)
Fop 1.3 (22MSM40017)
Theory 1.
If statement: If statement is used to decide whether a certain
statement or block of statements will be executed or not i.e if a
certain condition is true then a block of statement is executed
otherwise not.
Syntax: if (expression) {
#statement to execute if condition is true
}
Three ways to write the above statement: -
If the expression is true, the statement gets executed. But if the expression is
FALSE, nothing happens. The expression can be a logical/numerical vector, but
only the first element is taken into consideration. In the case of a numeric vector,
zero is taken as FALSE, rest as TRUE.
3. If-Else Statement
stop
2. Multiple Else-If
Statements Here we can check as many conditions as you like. But beware that the
conditions are tested from top to bottom. What this means is that first condition 1
is checked then 2, then 3 and so on. Only, if none of the requirements is met, else
gets executed. It may lead to slow processing of the code.
Syntax: - if (condition)
Else if
elseif
Else
If-else statements can also be nested. Nested means that one of the actions
itself contains another if-else statement. Important: the two if-else
statements are independent.
Syntax: -
if (condition){
} else {
}
4. Switch Statements In R,
the switch is also sometimes called the switch() function. A switch
statement checks a variable for equality against a predefined list of values.
The individual values in a list are also called as a case. A switch statement
can prove to be faster than if-else because the compiler knows that the case
constants carry the same type and it thus only tests for equality. Whereas in
case if-else, the compiler has no such knowledge.
Syntax: -
switch(expression,case1,case2,case3,…)
Practical implementation of all the Statements:
If statement:
2. If-Else Statements :
5 . Swift Function:
Practice Questions:
1. Write a program to check whether the day entered is Sunday.
2. Write a program to check if the student is pass or fail.
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the
faculty :
SI. NO. Parameters Marks obtained Maximum Marks
1.
2.
3.