C++ supports the usual logical conditions from mathematics:
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
Use if to specify a block of code to be executed, if a specified condition is true
Use else to specify a block of code to be executed, if the same condition is false
Use else if to specify a new condition to test, if the first condition is false
Use switch to specify many alternative blocks of code to be executed
Use the else statement to specify a block of code to be executed if the condition is false.
Syntax:
if (condition) { // block of code to be executed if the condition is true} else { // block of code to be executed if the condition is false}
Use the else if statement to specify a new condition if the first condition is false.
Syntax
if (condition1) { // block of code to be executed if condition1 is true} else if (condition2) { // block of code to be executed if the condition1 is false and condition2 is true} else { // block of code to be executed if the condition1 is false and condition2 is false}
Short Hand If...Else (Ternary Operator)
There is also a short-hand if else, which is known as the ternary operator because it consists of three operands. It can be used to replace multiple lines of code with a single line. It is often used to replace simple if else statements:
SYNTAX:
variable = (condition) ? expressionTrue : expressionFalse
What is C++?
C++ is a cross-platform language that can be used to create high-performance applications.
C++ was developed by Bjarne Stroustrup, as an extension to the C language.
C++ gives programmers a high level of control over system resources and memory.
The language was updated 4 major times in 2011, 2014, 2017, and 2020 to C++11, C++14, C++17, C++20.
Why Use C++ ?
C++ is one of the world's most popular programming languages.
C++ can be found in today's operating systems, Graphical User Interfaces, and embedded systems.
C++ is an object-oriented programming language which gives a clear structure to programs and allows code to be reused, lowering development costs.
C++ is portable and can be used to develop applications that can be adapted to multiple platforms.
C++ is fun and easy to learn!
As C++ is close to C, C# and Java, it makes it easy for programmers to switch to C++ or vice versa.
Watch video Conditions and If Statements|| C++ Complete Course || Beginners to Advance| Urdu/Hindi | BJM Techn online without registration, duration hours minute second in high quality. This video was added by user BJM Technologies 22 November 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 7 once and liked it people.