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

PDF 4

Uploaded by

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

PDF 4

Uploaded by

Yash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Decision Making 1

Decision Making
Terms
Boolean expression
Comparison operators
Conditional operator
If statement
Logical operators
Nesting if statements
Switch statement

Summary
• We use comparison operators to compare values.

• A Boolean expression is a piece of code that produces a Boolean value.

• With Logical operators we can combine Boolean expressions and represent more complex
conditions.

• With the logical AND operator (&&) both operands should be true. If either of them is
false, the result will be false.

• With the logical OR operator (||), the result is true if either of the operands is true.

• The logical NOT operator (!) reverses a Boolean value.

• Using if and switch statements, we can control the logic of our programs.

• An if statement can have zero or more else if clauses for evaluating additional
conditions.

Copyright 2022 Code with Mosh codewithmosh.com


Decision Making 2

• An if statement can optionally have an else clause.

• We can code an if statement within another. This is called nesting if statements.

• Using the conditional operator we can simplify many of the if/else statements.

• We use switch statements to compare a variable against different values.

• A switch block often has two or more case labels and optionally a default label.

• Case labels should be terminated with a break statement; otherwise, the control moves
to the following case label.

• Switch statements are not as exible as if statements but sometimes they can make our
code easier to read.

Copyright 2022 Code with Mosh codewithmosh.com


fl
Decision Making 3

Copyright 2022 Code with Mosh codewithmosh.com


Decision Making 4

Copyright 2022 Code with Mosh codewithmosh.com

You might also like