Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. C++ If-else condational statements | C++ Tutorials Bestitworriors
C++ If-else condational statements
C++ If-else condational statements | C++ Tutorials Bestitworriors - If-else use to check the condation base on value.If condation match the output the if block other wise output the else part.We can further add else-if to check further condations.If condation match then execute the code other wise it will further go to else block.The syntex is if(condation==value){// execute code } else {//code}.By using this syntex you can use multiple if-else in your code.
Some Key Points of C++ IF-Else
- If-else execute on condation base
- IF condation match then execute if block code
- If Condation don't match then execute else part
- We can use multiple if-else in code
- If-else is very easy to write code on condation base
- Inside if condation we check various condations
- Less than: a < b
- Less than or equal to: a <= b
- Greater than: a > b
- Greater than or equal to: a >= b
- Equal to a == b
- Not Equal to: a != b
Code
# include <iostream>
using namespace std;
int main()
{
int var1 = 20;
int var2 = 18;
if (var1 > var2)
{
cout << "var1 is greater then var2";
}
else if (var1 == var2)
{
cout << "var1 is equal to var2";
}
else
{
cout << " Var1 is less then var2";
}
return 0;
}
OutPut
var1 is greater then var2
OutPut
var1 is greater then var2
0 Comments