Hello everyone
today we will talk about if in C++
You can use these conditions to perform different actions for different decisions
The C++ programming language has the following selection statements:
Use if to specify a block of code to execute
if
a specified condition is true.Use
else
to define a block of code that executes if the first condition is false.If the first condition is false, use
else if
to specify a new condition to test.Use a switch to specify multiple alternative blocks of code to be executed.
The if statement.
if
- Use the if statement to specify a block of C++ code to execute if
a condition is true.
if (condition)
{
// block of code to be executed if the condition is true
}
Note that if written in lowercase letters. Converting to uppercase (IF or IF) will cause an error.
In the following example, we test two values to determine whether 20 is greater than 18. If the condition is true, print the text:
#include <iostream>
using namespace std;
int main()
{
int num 80;
int num1 = 70;
if(num > num1)
{
cout << "80 is greater than 70";
}
return 0;
}
Top comments (0)