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.

178<br />

Converting Data Types<br />

If the value of the Age variable is 1, this is how the Xor operator evaluates<br />

an answer:<br />

(Age > 2) XOR (Age >= 18)<br />

(1 > 2) XOR (1 >= 18)<br />

False XOR False<br />

False<br />

The Xor operator returns a False value if both values are False or if both<br />

values are True.<br />

Rather than use the word xor to represent the Xor operator, curly bracket<br />

languages, such as C/C++, use the caret (^) symbol instead.<br />

Boolean operators are used most often to make decisions in a program, such<br />

as a video game asking, “Do you want to play again?” When you choose<br />

either Yes or No, the program uses a comparison operator, such as<br />

Answer = “Yes”<br />

The result depends on your answer:<br />

✦ If your answer is Yes, the preceding comparison operation returns a<br />

True value.<br />

If this comparison operation is True, the video game plays again.<br />

✦ If your answer is No, the preceding comparison operation returns a<br />

False value.<br />

✦ If this comparison operation is False, the video game doesn’t play<br />

again.<br />

Converting Data Types<br />

Programming languages are often divided into two categories, depending on<br />

their variables:<br />

✦ A type-safe language <strong>for</strong>ces you to declare your variables, and their data<br />

types, be<strong>for</strong>e you can use them.<br />

See Chapter 2 in this mini-book <strong>for</strong> more in<strong>for</strong>mation about declaring<br />

variables types.<br />

✦ A typeless language lets you store any type of data in a variable.<br />

One moment a variable can hold a string, another moment it can hold an<br />

integer, and then another moment it might hold a decimal number.

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

Saved successfully!

Ooh no, something went wrong!