2.11 CONTROL STATEMENTS
So far, we have seen programs using assignment statements and library functions. If a programming language is to have only these statements, computer would be reduced to a calculator. Computers are powerful because they (program) can take a decision. Execute selectively. For this, language needs control statements.
2.11.1 if statement
A simple if statement has the following format:
- keyword “if”
- a condition in the brackets
- a statement (followed by the semicolon)
For example:
if ( condition ) statement ;
if (marks >=40) result = pass;
Please note that a parenthesis around the condition is mandatory. If the condition is true then the statement is executed, otherwise not. Ideally, conditions should be relational expression ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.