15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

580<br />

Using Operators<br />

Using Operators<br />

The three types of operators used are mathematical, relational, and logical.<br />

Mathematical operators calculate numeric results such as adding, multiplying,<br />

or dividing numbers. Table 4-3 lists the mathematical operators used in Pascal.<br />

Table 4-3<br />

Mathematical Operators<br />

Mathematical Operator Purpose Example<br />

+ Addition 5 + 3.4<br />

- Subtraction 203.9 - 9.12<br />

* Multiplication 39 * 146.7<br />

/ Division 45/ 8.41<br />

Div Integer division 35 div 9 = 3<br />

Mod Modula division (Returns the remainder) 35 mod 9 = 8<br />

Relational operators compare two values and return a True or False value.<br />

The six relational operators available in Pascal are shown in Table 4-4.<br />

Table 4-4<br />

Relational Operators<br />

Relational Operator Purpose<br />

= Equal<br />

Not equal<br />

< Less than<br />

Greater than<br />

>= Greater than or equal to<br />

Logical operators, as shown in Table 4-5, compare two Boolean values (True<br />

or False) and return a single True or False value.<br />

Table 4-5<br />

Logical Operator<br />

And<br />

Logical Operators<br />

Truth Table<br />

True And True = True<br />

True And False = False<br />

False And True = False<br />

False And False = False<br />

(continued)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!