I. operators
1. Variable
2. Operator**
3. Expression
1, variables
Variable explanation: the smallest storage unit (space) in programming. Its space size is determined by the data type when it is declared.
1.1 declaration: define a variable and tell Delphi the storage space of a name
1 var variable name: data type;
1.2. Variable initialization (first assignment of variable)
1 {assignment: variable name: = value of variable;}
1 //Variable to declare 2 var 3 Age:Integer;
1.3 initialize a variable
1 var 2 Name:string='Small black'; 3 Age := 0; 4 5 //Write out(Written console)Specified content 6 7 Writeln(6 / 4); 8 Writeln(6 div 2); 9 Writeln(6 mod 4); 10 11 //Read in a line from the console. Its main task now is to pause and wait for us to press enter. 12 Readln;
2. Operator
Arithmetic operator: + - * / (not divisible) div (divisible) mod (modulo, remainder)
Boolean operator:
Relational operator: < > (not equal to)
2.1. Examples of Boolean operators
1 Writeln(1 <> 2); 2 Writeln(not(1 <> 2)); 3 Writeln((1<2) and (2<3)); 4 Writeln((1<2) or (2<3));
2.2 XOR (exclusive or): the same is False and the different is True in the judgment condition
1 Writeln((1<2) xor (2<3)); 2 Writeln((1<2) xor (2>3));
3. Expression
3.1 expression: a sequence of operators and legal identifiers
Division: according to the type of operation result 1 < 2 1 + 1
3.2 statement: mainly composed of key words and operation instructions
Partitioning: select statements
if
case
Loop statement
3.3 statement format
1 begin 2 if 1<2 then 3 begin 4 //The code executed when the judgment condition is true 5 //Write a paragraph to the console 6 Writeln('hello Delphi'); 7 end; 8 9 //Read a line of text from the console until a carriage return (line break) is encountered 10 Readln; 11 end.
3.4. Shorthand: only one line of code needs to be executed
1 begin 2 if 1 < 2 then 3 Writeln('hello'); //In shorthand, begin end is omitted; 4 end;
3.5. If not
1 if 1<2 then 2 begin 3 Writeln('hello Delphi'); 4 end 5 else 6 begin 7 Writeln('hello,test'); 8 end; 9 //Read a line of text from the console until a carriage return (line break) is encountered 10 Readln; 11 end.
3.6 case statement
1 begin 2 //case The standard way to write sentences 3 i := 3; 4 case i of 5 1: //standard notation 6 begin 7 Writeln('test1,hello'); 8 end; 9 2: //Abbreviation 10 Writeln('Ruby Lin'); 11 else 12 begin 13 Writeln('Lin Chiling'); 14 end; 15 end; 16 Readln; 17 end.
3.7 define each process
3.7.1 student performance judgment
1 //Declare a process 2 procedure ComparingScore(); 3 //Specific implementation of the process 4 var 5 Score:Integer; 6 begin 7 //For students whose scores are more than 60, the output is qualified; for students whose scores are less than 60, the output is unqualified. 8 Writeln('Please enter a score:'); 9 Readln(Score); //Readln Can accept a variable, will accept Writeln('Please enter a score:')Medium to variable Score 10 if Score > 60 then 11 begin 12 Writeln('qualified'); 13 end 14 else 15 begin 16 Writeln('Unqualified'); 17 end; 18 end; 19 begin 20 //call 21 ComparingScore(); 22 Readln; 23 end.
3.7.2 print the season of the specified month.
1 {*------------------------------------------------------------------------------ 2 Prints the season that the month belongs to, based on the one used to specify the month. 3 3,4,5 Spring 6,7,8 Summer 9,10,11 Autumn 12,1,2 winter 4 @param Month Month to judge 5 -------------------------------------------------------------------------------} 6 procedure JudgmentIn(Month:Integer); 7 begin 8 if not ((Month > 0) and (Month < 13)) then 9 begin 10 Writeln('Month cannot be judged'); 11 Exit; 12 end; 13 14 if ((Month >= 3) and (Month <= 5 )) then 15 begin 16 Writeln('Spring'); 17 Exit; 18 end; 19 20 if (Month >= 6) and (Month <= 8) then 21 begin 22 Writeln('Summer'); 23 Exit; 24 end; 25 26 if (Month >= 9) and (Month <= 11) then 27 begin 28 Writeln('Autumn'); 29 Exit; 30 end; 31 32 if (Month = 12) or ((Month > 0) and (Month < 3)) then 33 begin 34 Writeln('winter'); 35 end; 36 37 end; 38 procedure JudgmentIn2(Month:Integer); 39 begin 40 case Month of 41 3: 42 begin 43 Writeln('Spring'); 44 end; 45 4: 46 begin 47 Writeln('Spring'); 48 end; 49 5: 50 begin 51 Writeln('Spring'); 52 end; 53 6: 54 begin 55 Writeln('Summer'); 56 end; 57 7: 58 begin 59 Writeln('Summer'); 60 end; 61 8: 62 begin 63 Writeln('Summer'); 64 end; 65 9: 66 begin 67 Writeln('Autumn'); 68 end; 69 10: 70 begin 71 Writeln('Spring'); 72 end; 73 11: 74 begin 75 Writeln('Autumn'); 76 end; 77 12: 78 begin 79 Writeln('winter'); 80 end; 81 1: 82 begin 83 Writeln('winter'); 84 end; 85 2: 86 begin 87 Writeln('winter'); 88 end; 89 90 91 else 92 begin 93 Writeln('Month cannot be judged'); 94 end; 95 96 end; 97 end; 98 begin 99 //call 100 //ComparingScore(); 101 // JudgmentIn(13); 102 JudgmentIn2(12); 103 Readln; 104 end.
3.7.3 judge whether it is Gao fushai
1 {*------------------------------------------------------------------------------ 2 @param Height height 3 @param Money money 4 @param Handsome Handsome 5 -------------------------------------------------------------------------------} 6 procedure MaleFemaleMarriage(Height: Integer;Money:Integer;Handsome:Boolean); 7 begin 8 if (Height>180) and (Money >= 10000000) and Handsome then 9 begin 10 Writeln('I must marry her'); 11 Exit; 12 end; 13 14 if (Height>180) and (Money>= 10000000) or Handsome then 15 begin 16 Writeln('Let's get married'); 17 Exit; 18 end; 19 20 if not((Height>180) and (Money>= 10000000) and Handsome) then 21 begin 22 Writeln('No marriage'); 23 Exit; 24 end; 25 26 end; 27 begin 28 //call 29 MaleFemaleMarriage(170,1000000,True); 30 Readln; 31 end.