C++ Tutorials

Visit for other information about c++ on tutorials point

IF ELSE STATEMENT


SAMPLE CODE

The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false. Here comes the else statement. We can use the else statement with if statement to execute a block of code when the condition is false.

A high-level programming language statement that compares two or more sets of data and tests the results. If the results are true, the THEN instructions are taken; if not, the ELSE instructions are taken. The following is a BASIC example:

In many languages, THEN is implied. All statements between IF and ELSE are carried out if the condition is true. All statements between ELSE and the end of the statement are carried out if not true. The following dBASE and C/C++ examples produce the same results as above.

IF STATATEMENT

SAMPLE CODE

An if statement is a programming conditional statement that, if proved true, performs a function or displays information. Below is a general example of an if statement, not specific to any particular programming language.

In the example above, if the value of X were equal to any number less than 10, the program would print, or display, "Hello John" on the console when the script is run. See the conditional statement definition for further information and some basic programming examples.

NESTED IF STATEMENT

SAMPLE CODE

A nested if is an if statement that is the target of another if statement. Nested if statements means an if statement inside another if statement. Yes, C++ allows us to nest if statements within if statements, it is also the block of code following the else statement is executed as the condition present in the if statement is false. nested-if. A nested if is an if statement that is the target of another if statement. Nested if statements means an if statement inside another if statement.

End of topic

Free Web Hosting