Ch4_Selection Structures

# Ch4_Selection Structures - 1 The Boolean Data Type • This...

This preview shows pages 1–7. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 The Boolean Data Type • This data type allows us to represent something as either True or False. • Syntax: Const flag = True; Var Variable_Name : Boolean • Example: Var Flag: Boolean Flag := True Writeln(Flag) (* will give as output True *) 2 Relational Operators Simple Boolean Expressions • Operators used for comparison are called “Relational Operators”, Examples: =, >, <, <=, >=, <> • A Boolean expression is an expression that takes a Boolean value (True / False) • Example – comparing two numbers or variables if they are equal • Note: Only data of the same type can be compared. 3 Relational Operators-Boolean Expressions (Priorities) • Note: operand1<>operand2 allows you to test if operand1 is different from operand2. 4 =, >, <, <=, >=, <> 3 +, - 2 / , *, Div, Mod 1 ( ) Priority Operator 4 Relational Operators-Boolean Expressions • A Boolean Expression can be assigned to a Boolean Variable. • Example: Var falg: Boolean; anInt: Integer; anInt := 10; Falg := (anInt>5);(*Flag has a boolean value True because anInt 10 is greater than 5*) 5 Logical Operator AND-OR Compound Expressions • Used to connect two Boolean expressions, thus composing one single expression. • Example: ( 3 > 2) And ( 5 > 4) (* True And True gives True *) ( 3 >2) Or (3 <2) (* True Or False gives True *) • When AND is used to join two expressions, the resulting compound expression is True only if both expressions are True. 6 Logical Operators AND-OR The NOT operator • When an Or operator is used to join two expressions, the resulting compound expression is FALSE only if both expressions are FALSE. expressions are FALSE....
View Full Document

## This note was uploaded on 11/04/2009 for the course SSE CSC 1400 taught by Professor Mhamdi during the Spring '09 term at Al Akhawayn University.

### Page1 / 23

Ch4_Selection Structures - 1 The Boolean Data Type • This...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online