CSCI 150
Home | | Course Schedule | | Assignments | | Lecture Notesprogram Hello; begin {your code goes here} end.
In place of {your code goes here} you would write the list of Pascal statements that you want executed in your program.
Comments are enclosed in brackets and are not part of the program. You should use comments to label your program with your name and section for every program you write. For example:
{Program: hello.pas Author: Brenda Student Class: CSCI 150, section 1 Date: 1/16/01 Assignment: Lab 1 Purpose: Write out "Hello World"} program Hello; begin writeln('Hello World!'); end.
2) Using writeln( )
Use the writeln( ) statement to write something to the monitor. The thing that you want to be written is
enclosed in single quotes:
3) Using variables and readln( )
Use readln( ) to read input from the keyboard. You will need to store that information somewhere, and we
use a variable for that. A variable is a name we give to a location in memory where we can store a value.
You can then use that name whenever you want to refer to that value.
program myName; var myName: string; {User's name} begin writeln('What is your name?'); readln(myName); writeln('Hello, ' + myName); end.
The word var at the beginning indicates a list of variables follows. The word 'myName' is the name of a variable to be created and the word 'string' indicates the variable is a string of characters (i.e. text, as opposed to a number). When we use a + in a writeln( ) statement, it causes the text to be concatenated. Thus in the above example 'Hello' will be joined with the value of the variable, myName (which will contain whatever the user typed in). Note that there is a comment after the variable that gives a brief description of the variable.