0% found this document useful (0 votes)
8 views

Conditional Statement

Chapter 3 discusses conditional statements in programming, emphasizing their role in decision-making similar to everyday life. It explains the structure of if-else statements, nested if statements for evaluating multiple conditions, and the switch statement for handling multiple execution paths based on specific values. The chapter highlights the importance of these constructs in creating intelligent programs that yield appropriate results based on given conditions.

Uploaded by

BSIT Siaton
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Conditional Statement

Chapter 3 discusses conditional statements in programming, emphasizing their role in decision-making similar to everyday life. It explains the structure of if-else statements, nested if statements for evaluating multiple conditions, and the switch statement for handling multiple execution paths based on specific values. The chapter highlights the importance of these constructs in creating intelligent programs that yield appropriate results based on given conditions.

Uploaded by

BSIT Siaton
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Chapter 3

CONDITIONAL
STATEMENTS
ABOUT

CONDITIONAL
STATEMENT
Everyday in our life we make decisions
whether our decisions are good or bad, it
all depends on the conditions that we
make. The same is also true in
programming. We use conditions to make
our programs intelligent enough to give us
the right results when we needed them
most.
IF-ELSE FLOW CHART
1. Test Condition:
• The program first evaluates the given
Test Condition.
2. True Branch:
• If the Test Condition is true, the
program executes the code within the
"Body of if" block.
3. False Branch:
• If the Test Condition is false, the
program executes the code within the
"Body of else" block.
4. Statement:
• Regardless of whether the Test
Condition was true or false, the
"Statement" will always be executed
after the If-Else block is complete.
NESTED IF
STATEMENT
Nested if refers to an if statement within an
if statement. When we write an inner if
condition within an outer if condition, then it
is referred to as a nested if statement in
java.
Nested if is a decision-making statement that
works similar to other decision-making
statements such as if, else, if..else, etc. It
executes a block of code if the condition written
within the if statement is true. However, in the
nested-if statement, the block of code is placed
inside another if block. And the inner block of
code will execute only when the outer condition
holds true.

Therefore, we use the nested if statement to


evaluate more than one condition in a program
and return multiple values depending on the
SWITCH
Unlike if and if-else statements, the switch
STATEMENT
statement can have a number of possible
execution paths. A switch works with the byte,
short, char, and int primitive data types. It also
works with enumerated types , the String
class, and a few special classes that wrap
certain primitive types: Character, Byte, Short
, and Integer.
The following code example, SwitchDemo,
declares an int named month whose value
represents a month. The code displays the
name of the month, based on the value of
month, using the switch statement.
In this case, August is printed to standard output.
The body of a switch statement is known as a switch block. A statement in the switch block can be labeled with
one or more case or default labels. The switch statement evaluates its expression, then executes all statements
that follow the matching case label.
Studio Shodwe

THANK YOU

www.reallygreatsite.com

You might also like