if-else Statement

Class:B.Com II yr
Subject:WebDesigning
Subject Type:OEL
Asst. Prof.Manju Kumawat

The if-else Statement

The if-else statement allows Java programs to handle both true and false conditions. If the condition inside the if statement evaluates to false, the else block is executed instead.

Using if-else statements in Java improves decision-making in programs by executing different code paths based on conditions.

Syntax of if-else Statement

Following is the syntax of an if...else statement −

if(Boolean_expression) { // Executes when the Boolean expression is true }else { // Executes when the Boolean expression is false }

If the boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed.

Flow Diagram

Below is the flowchart of the if-else statement, illustrating how it works:

If Else Statement

0 comments:

Post a Comment