Ask a Teacher
CAN WE USE IF STATEMENT ON CLASS ? WHY? |
The if statement can be used to test conditions so that we can alter the flow of a program. In other words: if a specific statement is true, execute some instructions. If not true, execute these instructions. In the following example the user can input a number. The number is stored in the variable A. Now take a look at the "??if statement?": if the number stored in the variable A is equal to ten, then "??is equal" is printed on the screen. Simple, isn'??t it. If the number is not equal to ten, then nothing is printed. Take a look at the example: #include<iostream> using namespace std; int main() { int A; cin >> A; if ( A == 10 ) cout << "is equal" << '\n'; return 0; } |