Académique Documents
Professionnel Documents
Culture Documents
5.1Condition
5.2 Selection
5.3 Iteration
Computer and Information
Technology for (HKCEE)
Module A2: Part B
5.1 Condition
Condition
a logical expression (e.g. x>0) which evaluates
to either true or false
Input Num
False True
Condition
Process 1 Process 2
5.1 Condition
Logical operators / Boolean operators
=,>,<,>=,<=,<>,NOT
AND operator
true only if both operands are true
OR operator
true if at least one of the operands are true
5.1 Condition
(Note: Assume x = 3)
© Longman Hong Kong Education Page4
Computer and Information
Technology for (HKCEE)
Module A2: Part B
5.1 Condition
5.1 Condition
Negation of equality
NOT(p=q)is equivalent to p<>q
Negation of comparison operators
5.2 Selection
IF-THEN-ELSE statement
IF ( condition ) THEN
statement(s)
ELSE
statement(s)
IF-THEN statement
IF ( condition ) THEN
statement(s)
5.2 Selection
Nested control structure
consist of one control statement embedded within
another control statement
5.2 Selection
Nested IF statement
IF ( condition ) THEN
IF ( condition ) THEN
IF ( condition ) THEN
statement(s)
ELSE
statement(s)
ELSE
statement(s)
ELSE
statement(s)
© Longman Hong Kong Education Page9
Computer and Information
Technology for (HKCEE)
Module A2: Part B
5.2 Selection
CASE statement
a composite statement used to make a decision
between many alternatives
CASE ( expression ) OF
1: statement(s)
2: statement(s)
3: statement(s)
ELSE
statement(s)
5.3 Iteration
Loop
a control structure that causes a set of
statements to be repeated
The while loop
WHILE (condition) DO
BEGIN
statement(s)
END
where condition is for testing if the loop should continue
5.3 Iteration
WHILE-DO loop performs
initialise a value
test the loop condition
increment/decrement the value
Increment
i := i +1;
increment = 1
5.3 Iteration
Counter-controlled loop
a loop that executes a specified number of times
Incrementation
Count := 1; {Initialisation}
WHILE Count <= 10 DO {Test}
BEGIN
(statements) {Repeated
actions}
Count := Count + 1 {Incrementation}
END
5.3 Iteration
Counter-controlled loop
Decrementation
Count := 10; {Initialisation}
WHILE Count > 0 DO {Test}
BEGIN
(statements) {Repeated
actions}
Count := Count - 1 {Decrementation}
END
5.3 Iteration
The FOR-TO-DO statement
control variable is incremented by 1 for each loop
FOR <variable identifier>:= <initial value> TO
<finial value> DO
statement(s)
The FOR-DOWNTO-DO statement
control variable is decremented by 1 for each loop
FOR <variable identifier>:= <initial value> DOWNTO
<finial value> DO
statement(s)
5.3 Iteration
Nested loops
BEGIN
FOR <variable identifier>:= <initial value> TO
<finial value> DO
BEGIN
FOR <variable identifier>:= <initial value>
TO <finial value> DO
statement(s)
END
END
© Longman Hong Kong Education Page16
Computer and Information
Technology for (HKCEE)
Module A2: Part B
5.3 Iteration
WHILE-DO loop
test a condition at the beginning of the loop
pretest loop
WHILE (entry condition) DO
statement(s)
5.3 Iteration
WHILE-DO loop
True
condition loop body
False
5.2 Iteration
REPEAT-UNTIL loop
execute at least once
posttest loop
REPEAT
loop body
statement(s)
UNTIL(conditions) False
condition
True
END