CSCI 150
Home | | Course Schedule | | Assignments | | Lecture Notes
Each block of program code should be indented to show that the lines of
code belong together. The best rule of thumb is to indent after each
begin, and un-indent at each end statement. Note that for nested blocks
you need to indent again (e.g. an if statement within a loop or a loop
within a loop). Also indent after the
var statement. Several examples follow:
Program indentation
{program: CoolDude.pas Author: Brenda Student Class: CSCI 150, Section 01 Date: 2/19/01 Assignment: Lab 7 Purpose: Performs really cool dance moves} program CoolDude; var dance: string; {Name of dance} steps: integer; {number of steps to perform} begin writeln('Enter the name of the dance: '); readln(dance); writeln('Enter number of steps: '); readln(steps); writeln('I am a dancing fool!'); end. {end CoolDude program}
Indenting conditionals and loops
{program: Astrology.pas Author: Brenda Student Class: CSCI 150, Section 01 Date: 2/12/01 Assignment: Homework 4 Purpose: Write a person's horoscope.} program Astrology; var integer: month, day, year; {Birthday of user} count: integer; {counter for loop} begin writeln('Please enter your birthdate: '); readln(month); readln(day); readln(year); for count := 1 to 12 do begin writeln('This is month number ' + count); writeln('This is your lucky month); end; for count := 1 to 12 do begin if count = month then begin writeln('You will meet a tall, dark stranger.'); end; end; if day = 13 then begin writeln('You will suffer a misfortune'); end else begin writeln('You were born under a lucky star'); writeln('You will have a charmed life.'); end; end. {end of Astrology program}