Skip to main content

Posts

Showing posts with the label increment operator

Conditional statements

In the last post , we saw about data types and and variables. What we have not discussed is pointers and references. We discuss that along with constants in a future post. Now let us talk about control structures. If you already know a programming language like C or Java, you can skip this post. Conditional Statements C++ has 2 conditional statements and one conditional operators. These are if, switch and ?: if statement If statement is used to test a condition and execute a statement if the condition is true. There can be an optional else statement which gets executed if the condition is false. Syntax : if (condition)       statement1; else      statement2;  Let us look at some examples int m; cin >> m; if (m > 0 ) cout << "You have entered a positive number" << endl; else cout << "The number you typed is non-positive" << endl; Note that if and else should be f...