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.

576<br />

The Structure of a Pascal Program<br />

Although it’s unlikely that Pascal will ever regain its popularity as a major<br />

<strong>programming</strong> language, Pascal has inspired other <strong>programming</strong> languages,<br />

most notably the Ada <strong>programming</strong> language, which is used in critical, realtime<br />

systems, such as the Boeing 777 avionics system. As a result, Pascal<br />

remains an influential <strong>programming</strong> language to this day.<br />

The Structure of a Pascal Program<br />

The strength (or weakness, depending on your point of view) of Pascal is<br />

that it <strong>for</strong>ces you to structure your programs. At the beginning of a Pascal<br />

program, you must declare any constants, types, or variables, such as<br />

Program name;<br />

Const<br />

(* Constants here *)<br />

Type<br />

(* Type definitions here *)<br />

Var<br />

(* Variable declarations here *)<br />

Begin<br />

(* Commands here *);<br />

End.<br />

A typical Pascal program might look like this:<br />

Program TaxRefund;<br />

Const<br />

TaxRate = 0.35;<br />

Type<br />

ClassLevel = (Upper, Middle, Lower);<br />

Var<br />

MyClass : ClassLevel;<br />

TaxesOwed, Income : integer;<br />

Begin<br />

Income := 60000;<br />

TaxesOwed := Income * TaxRate;<br />

If MyClass = Upper then<br />

Begin<br />

Writeln (‘Bribe a corrupt politician.’);<br />

End;<br />

End.<br />

Pascal ends every statement with a semicolon but uses a period at the end<br />

of the entire program.

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

Saved successfully!

Ooh no, something went wrong!