sd & d conditional statements

14
Conditional Statements

Upload: forrester-high-school

Post on 19-Aug-2015

88 views

Category:

Education


1 download

TRANSCRIPT

Conditional Statements

Conditional StatementsComputer programs need to make decisions.

We use a conditional statement in programming to test whether or not something is true.

A conditional statement takes the form IF…THEN…

IF something is true THEN do something

Pseudocode

LiveCode

Pseudocode

LiveCode

ElseThe ELSE statement can be used with the IF statement to provide an alternative outcome from the condition.

The conditional statement can be extended to take the form IF…THEN…ELSE

IF something is true THENdo something

ELSEdo something different

Pseudocode

LiveCode

Multiple ConditionsIt is possible to further extend the conditional statement to test for more than one condition.

IF something is true THENdo something

ELSE IF something else is true do something different

ELSE IF something else again is true do something different

etc

Pseudocode

LiveCode

Comparison OperatorsSo far we have tested to see if two things are equal, but there are other comparison operators we can use.

Operator Description

= Equal to

< Less than

> Greater than

<= Less than or equal to

>= Greater than or equal to

<> Not equal to

Pseudocode