The Logical Or: Semesteraverage 90

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

The Logical OR 

 
In the last guide, we talked about the ​LOGICAL NOT​ and the​ LOGICAL AND​ operator. Today we 
are going to talk about the ​LOGICAL OR ​operator. The logical or is denoted by ​||​. 
 
Suppose you are a student at a university. You sit for your math final exam. Now, if you get 90% in 
your final exam of the subject ​or​ if you get 90% in the overall subject, you get an A. Let’s see this in 
code: 
 
int semesterAverage = 85;
int finalExamMark = 92;

if (​semesterAverage >= 90​ || ​finalExam >= 90​) {


printf(“Student got an A.\n”);
} else {
printf(“Student didn’t get an A.\n”);
}

The output of the above code will be ​Student got an A.​ This is because one of the conditions inside 
the if-statement is true that is finalExamMark >= 90 is true. The definition goes like this: if ​either or 
both ​condition is true, execute the if-statement. Otherwise, if both conditions are ​false ​(conditions 
are marked in red and green) execute the else statement. 
 
OR 
Condition 1 inside if  Condition 2 inside if  Which statement will be 
executed 

true  true  If statement executed 

true  false  if statement executed 

false  true  if statement executed 

false  false  Else statement executed 

You might also like