0% found this document useful (0 votes)
36 views

If Statements in C++

The document discusses C++ code for including header files and namespaces, defining the main function, and using cin. It then explains that if statements allow programmers to control program flow based on conditions being true or false. Various comparison operators for if statements are listed such as >, <, >=, <=, ==, and !=. An example if statement is provided to check if a condition is true or false and execute different code blocks accordingly.

Uploaded by

SalmaAn Malik
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

If Statements in C++

The document discusses C++ code for including header files and namespaces, defining the main function, and using cin. It then explains that if statements allow programmers to control program flow based on conditions being true or false. Various comparison operators for if statements are listed such as >, <, >=, <=, ==, and !=. An example if statement is provided to check if a condition is true or false and execute different code blocks accordingly.

Uploaded by

SalmaAn Malik
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

The #include is a "preprocessor" directive that tells the compiler to put code from the header called

iostream into our program before actually creating the executable.

"using namespace std”, This line tells the compiler to use a group of functions that are part of the
standard library (std).

The next important line is int main(). This line tells the compiler that there is a function named main, and
that the function returns an integer, hence int.

The next command is cin.get()

If statements in C++
The ability to control the flow of your program, letting it make decisions on what code to execute, is
valuable to the programmer. The if statement allows you to control if a program enters a section of code
or not based on whether a given condition is true or false.

> greater than 5 > 4 is TRUE


< less than 4 < 5 is TRUE
>= greater than or equal 4 >= 4 is TRUE
<= less than or equal 3 <= 4 is TRUE
== equal to 5 == 5 is TRUE
!= not equal to 5 != 4 is TRUE

If (a=10)
if ( TRUE ) {
// Execute these statements if TRUE
}
else {
// Execute these statements if FALSE
}

You might also like