What Will I Learn?
We learn how to using Variables, Constants and Types on Free Pascal
- You will learn Example "basic code pascal"
Uses crt;
Begin
Writeln(‘Types by Raghib’);
End.
- You will learn Example " Variables"
Uses crt;
Var utopian : string;
Begin
utopian := ' Variables by raghib’;
Writeln('utopian');
End.
- You will learn Example "Constants"
Uses crt;
Const bb=’constant by raghib’;
Begin
Writeln(bb);
End.
Requirements
Free Pascal
Difficulty
- Basic
Tutorial Contents
A full description of the topics of this video tutorial, plus the contents of the tutorial itself.
Introduction To Pascal
The Pascal programming language is a high-level programming language (High-Level Programming Language). It is called so because the program syntax is easy to understand by humans or close to human language. Unlike the mnemonic code or machine language that is very difficult to understand by most people.
Broadly speaking, the listing program in Pascal is divided into three parts, namely:
- The head of the Program
The head of the program is a line that indicates the title of the program or the identity of the program. This section is optional or not should be made. Is rendered as follows:
Program [title_program];
Declaration
Part of the Declaration is the part that contains the definition of constants, variables, types, labels, function or procedure.The core of the program
The core of the program, namely the main program listings that will be compiled and will be executed into a program. This section contains the algorithm-programming algorithm and other commands.
To initiate introductions with Pascal, then note in advance the following syntax:
Begin
Write (' First Course '); Readln;
End.
The above program will produce a "first course" on the screen of the monitor. Note the syntax above is on the second line is an expression of one statement. In Pascal we will know IE expression is a command-command to be run a certain function, the expression may amount to one statement, and more.
A statement is a command in Pascal which is marked with a sign semicolon (;), one statement can only be either a semicolon marks only. For an expression that requires more than one statement, then use the following syntax:
Begin
Statement-statement;
End;
Note that the sign of the end of the token ' end ' is a semicolon instead of a point. Major programs in Pascal always starts with the word ' begin ' and end with '. '.
Program 1: Print the writing to the screen of the Monitor
Create the following program:
Uses crt; Begin
Uses crt;
Begin
Writeln('We learn tutorial Pascal ');
Write('Variable ');
Writeln('Type');
Writeln('Constant');
Readln;
End.
Note the above program the program above will result in the output
In the above program, the command writeln prints the text that is in brackets/parentheses and then places the cursor on the next line, while the command write has the same functionality but this command puts the cursor on the same line.
To better understand the use of write and writeln, we try make this program at home and watch what is produced:
Uses crt;
Begin
Writeln('test write');
Write('one ');
Write('for all');
Write('the best');
Write('for life');
Writeln();
Writeln();
Writeln('two');
Write('we ');
Write('love ');
Write('Free Pascal');
Readln;
End.
result in the output
Using Constants and variables
Pascal programming on known several variables, each variable has a data type that is different and has different properties.
Note the following three programs: 1.
Uses crt;
Begin
Writeln (‘hello raghib’);
End.
Uses crt;
Var sentence: string; Begin
Sentence: = ' introduction Pascal ';
Writeln (sentence);
End.
Uses crt;
Const sentence = ' Introduction Pascal with const ';
Begin
Printf (sentence);
End.
The third program above will have the same result. But some differences on the writing program. On program 1, the writing will be printed directly on the screen.
On the Select program 2 on a variable, that variable is of type string sentence. String type that is the data type that contains a collection of characters and not a numeric value, or in other words is a value that cannot be operation arithmetic like addition, subtraction, multiplication, and more. On the variable and then filled in a value, namely the word ' computer science ' Unila. Then printf command prints the value of the variable sentence. Write printed in accordance with the value of the variable, then if the value changed, printed results will change.
On program 3, look like similar to the first program. But the difference, which is used in this program is not a variable. When the note is indeed almost similar, but surely there is a difference on both. On this program being used is constant. The value of constants will not change, unlike a variable.
Posted on Utopian.io - Rewarding Open Source Contributors