10
1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

Embed Size (px)

Citation preview

Page 1: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

1© 2002 John Urrutia. All rights reserved.

Qbasic Chapter 4

IF Statementsand

READ & DATA

Page 2: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

2© 2002 John Urrutia. All rights reserved.

Boolean or Logical Expressions

Algebra created by George Boole

Always evaluates to a binary stateGenerally:

1 is TRUE0 is FALSE

Page 3: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

3© 2002 John Urrutia. All rights reserved.

Relational ExpressionsSingle relational operator two operands

< Less than

> Greater than

= Equal to

<= Less than or equal to

>= Greater than or equal to

<> Not equal to

Page 4: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

4© 2002 John Urrutia. All rights reserved.

One-way SelectionDown the primrose path or another IFy

situation.

IF condition THEN

statement(s)

END IF

Page 5: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

5© 2002 John Urrutia. All rights reserved.

Two-way SelectionThere’s more than one-way to skin

a turkey.IF condition THEN

statement(s)

ELSE

statement(s)

END IF

Page 6: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

6© 2002 John Urrutia. All rights reserved.

Nested IF StatementsIF condition THEN

IF condition THENstatement(s)

ELSEstatement(s)

END IFELSE

statement(s) END IF

Page 7: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

7© 2002 John Urrutia. All rights reserved.

Multi-way SelectionIF condition THEN

statement(s)ELSEIF condition THEN

statement(s)ELSEIF condition THENstatement(s)

ELSEstatement(s)

END IF

Page 8: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

8© 2002 John Urrutia. All rights reserved.

Logical OperatorsOp-1 Op-2 AND OR XOR

True True True True False

True False False True True

False True False True True

False False False False False

Page 9: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

9© 2002 John Urrutia. All rights reserved.

Operator PrecedenceOrder of evaluation

^ Exponent

+ or - Unary (sign)

*, /, \, MOD Arithmetic

<, >, <=, Relational operators>=, <>, =

NOT, AND, Logical operatorsOR, XOR

Page 10: 1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA

10© 2002 John Urrutia. All rights reserved.

DATA & READ statementsDATA const, const, const, …

Provides internal storage

Accessed sequentially

READ var, var, var, …Populates variables from DATA

RESTORE labelResets the some or all the DATA