15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2: Variables, Data Types,<br />

and Constants<br />

In This Chapter<br />

Declaring your variables<br />

Defining data types<br />

Storing and retrieving data in a variable<br />

Using constant values in variables<br />

Defining a variable’s scope<br />

Every program consists of a list of instructions that tell the computer<br />

what to do. The simplest program consists of a single instruction,<br />

such as one that tells the computer to display the words, Hello, world!<br />

on-screen.<br />

Of course, any program that does the same thing over and over again isn’t<br />

very useful or interesting. What makes a program useful is when it can<br />

accept in<strong>for</strong>mation from the outside world and then respond to that<br />

in<strong>for</strong>mation.<br />

So instead of just displaying Hello, world! on-screen, a more useful program<br />

might ask <strong>for</strong> the user to type his name in so the program could display<br />

Hello, Bob!<br />

Programs don’t always have to get in<strong>for</strong>mation from a person. Sometimes,<br />

programs can retrieve data that’s stored somewhere else, such as a list of<br />

employees stored on another computer.<br />

That program could access this database over a network and determine<br />

which person has been assigned to which computer in the building. Then<br />

the program can retrieve each person’s name so when he turns on the computer,<br />

the program displays his name on his screen.<br />

An even more sophisticated program could work with a Web cam hooked up<br />

to the computer along with a database that includes employee names and<br />

their photographs. So every time any computer’s Web cam spots someone<br />

sitting at the computer, the program could examine the person’s image

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

Saved successfully!

Ooh no, something went wrong!