1. Constant : Fixed value, not variable.
1) const
Constant name = constant value (expression);
2) resourcestring
Constant name = string (constant);
2. Variables
1) definition
Var Name 1, Name 2, ... Name N: type;
2) naming principles (reference)
Variable name = type (abbreviation) + scope (abbreviation) + exact meaning name
3) Three kinds of assignment formats
Variable name: = value;
Variable Name 1: = variable 2;
Variable name: = Call of procedure or function;
3. Type Constants
1) A type constant is a global variable and is not a constant, it has a pre-initialized value.
2) Definition
Const
Name: type = value;
3) Kind
Simple Type Constants
Array type Constants
Record Type constants
Collection type Constants
Pointer type Constants
Procedure Type Constants
4. Data type
Easy Type (simple) |
|
|
|
|
Ordered type (Ordinal) |
|
|
|
|
Integers (integer) |
|
|
|
Character (Character) |
|
|
|
Boolean (Boolean) |
|
|
|
Enumeration (enumerated) |
|
|
|
Subdomain (SubRange) |
|
|
Reals (Real) |
|
|
Structure type (structured) |
|
|
|
|
Collection (SET) |
|
|
|
Arrays (Array) |
|
|
|
Records (record) |
|
|
|
Document (file) |
|
|
|
Classes (Class) |
|
|
|
Class pointer (Reference) |
|
|
|
Interface (Interface) |
|
|
String type (String) |
|
|
|
Pointer type (Pointer) |
|
|
|
Process type (procedural) |
|
|
|
Variable type (Variant) |
|
|
|
5. User-defined type
Subdomain type
Type name = initial value ... Final value;
Enum type
Type name = (value 1, value 2, value 3 ...) Value n);
Array type
type name = Array[subscript definition]of type name
Type name = [subscript definition 1, subscript definition 2 ... Subscript defines n] of element types
or name = [subscript definition 1 of... Array [Subscript definition N] of element types
Collection type
Type name = Set of element types
Pointer type
Type name = ^ Node type
Record type
Type name = Record
Domain 1: type;
Domain 1: type;
......
Domain N: type;
End;
File type
Type name = file of element types
Statement
Simple Statement
X: = Y + Z; Assignment
Randomize; Procedure Call
Compound statement
Begin
A: = B;
C: = A * 2;
End
End of the last statement before the end of the semicolon is not required, you can write:
Begin
A: = B;
C: = A * 2
End
Assignment Statements
In the Pascal language, the assignment statement uses the colon-equal-sign operator ": =",
conditional Statements
If statement
For the If-then type statement, the statement executes only when the condition is satisfied;
If Checkbox1.checked Then
ShowMessage (' CheckBox1 is checked ')
For the If-then-else type, the IF statement selects one of the two statements to execute
If Checkbox2.checked Then
ShowMessage (' CheckBox2 is checked ')
Else
ShowMessage (' CheckBox2 is not checked ');
Note that you cannot precede the first sentence with a semicolon before the Else keyword, or the compiler will tell you the syntax error. In fact, the If-then-else statement is a simple statement, so you cannot add a semicolon to the middle of the statement.
If statements can be complex, the conditional part of a sentence can be a series of conditions (joined with Boolean operators such as and, or, not), and the If statement can also nest another if statement
Begin
Compound If statement
If Checkbox1.checked Then
If Checkbox2.checked Then
ShowMessage (' CheckBox1 and 2 are checked ')
Else
ShowMessage (' CheckBox1 is checked ')
Else
ShowMessage (
' Checkbox1 isn't checked, who cares for Checkbox2? ')
End
Case statement
A case statement includes an expression that is used to select a value, a sequence of possible values, or a range of values. These values should be constants, and they must be unique and should belong to an ordered type.
The case statement can end with an else statement that executes an else statement when none of the tags match the value of the selector. Here are two simple examples:
Case Number of
1:text: = ' one ';
2:text: = ' both ';
3:text: = ' three ';
End
Case MyChar of
' + ': Text: = ' Plus sign ';
'-': Text: = ' minus sign ';
' * ', '/': Text: = ' multiplication or division ';
' 0 ' ... ' 9 ': Text: = ' number ';
' A ' ... ' Z ': Text: = ' lowercase character ';
' A ' ... ' Z ': Text: = ' uppercase character ';
Else
Text: = ' Unknown character ';
End
the cycle in Pascal's language
Looping statements used in other programming languages, in the Pascal language, include for, while, and repeat statements. If you have used other programming languages, you will find that the loop statements in Pascal are nothing special, so I'll just give you a brief explanation here.
For loop
The For loop in Pascal is strictly based on the counter, and each time the loop is executed, the counter does not increment a value or decrease it by one value. The following is a brief example of a for statement that adds the first 10 numbers together:
Var
K, I:integer;
Begin
K: = 0;
For I: = 1 to Ten do
K: = k + I;
The same for statement can be written with exactly the opposite counter:
Var
K, I:integer;
Begin
K: = 0;
For I: = ten Downto 1 do
K: = k + I;
The FOR Loop statement in Pascal is less flexible than other languages (it cannot specify a step other than 1), but it is easy to understand. If the conditions to be judged are more complex, or if you want to customize the counters, you can use a while statement or a repeat statement instead of a For loop statement.
Note: The For loop counter does not have to be a number, it can be any ordinal type of value, such as a character or an enumeration type value.
While statements and repeat statements
The difference between the while-do loop statement and the Repeat-until statement is that the code for the repeat Loop statement is executed at least once. This is easy to understand from the simple example below
:
while (I <=) and (J <=) do
Begin
Use I and J to compute something ...
I: = i + 1;
J: = j + 1;
End
Repeat
Use I and J to compute something ...
I: = i + 1;
J: = j + 1;
Until (I >) or (J > 100);
Visible from above even if the initial value of I or J is greater than the code in the 100,repeat-until loop, it will still execute once.
Note: Another key difference between the two loops is that the condition of the Repeat-until loop is the reverse condition, as long as the condition is not met, the loop executes, and the loop terminates when the condition is met. This is exactly the opposite of the while-do cycle, where the while-do loop executes when the condition is true. To do this, I had to get the same result in reverse condition in the code above.
Note: Using the break and Continue system procedures can change the standard process of loop execution. Break interrupt loop; Continue jumps directly to the loop test sentence, or increments the counter by one step, and then resumes the loop (unless the condition is empty or the counter reaches the maximum value). There are also two system procedures, Exit and Halt, that let you immediately return from a function or procedure, or terminate the program.
With statement
With BirthDay do
Begin
Year: = 1995;
Month: = 2;
Day: = 14;
End
Transfer from http://blog.csdn.net/tercel99/article/details/672910