Lost Password?


  #1 (permalink)  
Old 03-10-2008, 08:50 PM
PascalPro PascalPro is offline
Newbie
 
Join Date: Mar 2008
Posts: 13
Credits: 13
Rep Power: 0
PascalPro is on a distinguished road
Default Pascal Tutorial

Welcome, I know that Pascal is not very muched talked about on the forums here much anymore but I think it is a great place to start your programming experiance! Lets begin.

What You Will Need:

Pascal Compiler (Just Google "Free Pascal", this is the compiler I use)
The will to learn!

Your first program:

Your first program will be the traditional "Hello World" Program.
Here is the information you will need for the making of the program.

"Write" command. The write command will do exactly what it sounds like it will do. It will write the text onto the screen! To use it you must use the following format

Code:
Write('Put your text here!');
Notice the semicolon at the end. You will be putting these at the end of most all commands. All Pascal programs will contain the following
Code:
Program ProgramName;
Begin
End.
So, you first program should look like this:

Code:
Program HelloWorld; (* The title of the program *)
begin
Write('Hello World'); (* Executable commands *)
end.
Comments are always put between (* *). Now we must compile the program. To do this you can probably use the F9 key. If you get any errors go back through to see where you messed up. Now if you do compile succesfully then press CTRL + F9 to run the program. Congratulations! Your very first program. I will be updating this tutorial tomorrow.

Next Lesson: Asking questions to the user and returning the feedback!

Last edited by PascalPro; 03-10-2008 at 08:52 PM. Reason: To fix a typo.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-16-2008, 09:40 AM
PascalPro PascalPro is offline
Newbie
 
Join Date: Mar 2008
Posts: 13
Credits: 13
Rep Power: 0
PascalPro is on a distinguished road
Default Re: Pascal Tutorial

Welcome!

In this lesson we will be teaching you how to ask questions and return feedback. Before we do that you must learn the basics of variables. There are many types of variables : string (A series of characters), integer(between about -30000 to +30000, numbers), and Boolean ( Has two values, true of false) To define variables we must use this format :
Code:
var
MyName : String; (* Sets the variable 'MyName' as a string *)
MyAge : Integer (* Sets the variable 'MyAge as a integer *)
AreYouRich : Boolean; (* Sets the variable 'AreYouRich' as a Boolean *)
Variables always come after the program name and before the 'Begin'. There are other variables like ShortInt, LongInt, Extended, Real, and Array. We wont cover these until later in the tutorial. If you have 2 or more integer variables you can put them on the same line seperated by a comma like so :
Code:
var
MyAge, MomsAge, DadsAge : Integer;
Now! You will ask your first 'Pascal' question. We must always start with Program name and begin. Now, will the answer to your question be a string, integer, or boolean? In this example we will use string. So you have your variables and your code should look like this
Code:
Program CopyCat;

var
WhatToCopy : String;
Now we will use the write command to ask a question.

Code:
Program CopyCat;

var
WhatToCopy : String;

begin
Write('What would you like us to copy? ');
Readln(WhatToCopy);
The write command asks the question. When the user types in a answer, the answer is then saved in the WhatToCopy variable by the readln command. Readln usually comes before the write command. Now you have the answer stored, so how are you going to sent it back out? With write of course. Your final program should look like this

Code:
Program CopyCat;

var
WhatToCopy : String;

begin
Write('What would you like us to copy? ');
Readln(WhatToCopy);
Writeln(WhatToCopy);
Readln;
End.
The readln before the main 'End.' makes the characters on the screen stay until the user presses enter. Now copy and paste this into your compiler. Presto! Notice how when your question and answer shows up the is stuff at the top. If you want to get rid of it we use the crt command which is defined as a use before the variable like so :
Code:
Program Uses;

uses
crt;

var
(* All variables here *)

begin
(* Code goes here *)
End.
If you would like to use the crt use to clear the screen your final program would look like this :

Code:
Program CopyCat;

uses
crt;

var
WhatToCopy : String;

begin
ClrScr; (* Clears screen and makes program easier to read *)
Write('What would you like us to copy? ');
Readln(WhatToCopy);
Writeln(WhatToCopy);
Readln;
End.
Just remember that uses come before variables so if you compile code like this

Code:
var
(* Put Variables Here *)

uses
crt;
You will get an error! Have fun until next time!

Next Lesson Includes : Procedures

Happy Programming!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Visual Studio 2008 Obfuscating with Dotfuscator Jordan Tutorials 5 11-16-2008 03:05 PM
Tutorial - ListBox, ComboBox & Command button. travy92 VB Tutorials 9 07-06-2008 12:48 AM
CodeCall Tutorial Contest #4 Jordan Announcements 29 02-25-2008 12:25 PM
John's Java Tutorial Index John Java Tutorials 0 01-11-2007 04:05 PM


All times are GMT -5. The time now is 01:02 PM.

Contest Stats

WingedPanther ........ 2672.3
Xav ........ 2600.07
Brandon W ........ 1701.26
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 959.05
dcs ........ 650.52
Steve.L ........ 475.59
orjan ........ 409.29
chili5 ........ 380.6

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads