What is the difference between if and if-else statement ?

What is the difference between if and if-else statement ?

What is the difference between if and if-else statement ?

With the if statement, a program will execute the true code block or do nothing. It is little bit different from switch statement as it can decide between two in normal conditions.

With the if/else statement, the program will execute either the true code block or the false code block so something is always executed with an if/else statement.

Why do we use nested if -else structure ?

Ans:  When a series of decision is required, nested if-else statement is used.

Nesting means using one if-else construct within other .

Write down a program for testing either a given number is +ve or –ve.

if-else
if-else

if-else statement
if-else statement
if-else example
if-else example

Create the equivalent of a four-function calculator. The program should request the user to enter a number, an operator, and another number. (Use floating point) It should then carry out the arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers

calculator example
calculator example
calculator example
calculator example
calculator example output
calculator example output

 

For more read here:

https://eevibes.com/computing/object-oriented-programming/what-are-the-conditional-statements-in-programming/

What are the decision making statements in programming?

Leave a Reply

Your email address will not be published. Required fields are marked *