AND vs. OR

In programming languages, you can add multiple checks to the if parameter.This can be used to carry out specific tasks if particular conditions have been met.

However, if you use AND, all of the conditions will have to be met for the condition to be true.

These checks can also be used to meet particular conditions, such as with OR, where only one of the statements needs to be true.

C++

In C++, && is used to denote AND, and || is used to denote OR.

Let’s write a C++ code that prints “All is Good” if the fruit is an apple and if the vegetable is spinach. If only one of the conditions match, it will print, “Something is fishy.”

#include <iostream>
#include <string>
using namespace std;
int main() {
string fruit = "apple";
string vegetable = "spinach";
if(fruit == "apple" && vegetable=="spinach")
cout<<"All is Good"<<endl;
else if(fruit == "apple" || vegetable=="spinach")
cout<<"Something is fishy"<<endl;
}

Python

In Python, and is used to denote AND, while or is used to denote OR.

Let’s write a Python code that prints “All is Good” if the fruit is an apple and if the vegetable is spinach. If only one of the conditions match, it will print, “Something is fishy.”

fruit = "apple"
vegetable = "spinach"
if(fruit == "apple" and vegetable=="spinach"):
print("All is Good")
elif(fruit == "apple" or vegetable=="spinach"):
print("Something is fishy")
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved