The if statement primarily detects a condition and executes a piece of code based on whether the condition is true or false;
| 1234567891011121314151617 |
var I: Integer; FileGood: Boolean;begin FileGood := True; ifFileGood then{ 简洁的写法,判断FileGood是否为True} ShowMessage(‘True‘); { 上面的写法等同于下面} ifFileGood = Truethen ShowMessage(‘True‘); ifI > 0then{ 如果I大于0} DoSomething1 elseifI < 0 then{ 如果I小于0,else if块不是必须的} DoSomething2 else{ 如果是其他条件,通常来实现默认的处理,else块也不是必须的} DoSomething;end; |
The case statement can be thought of as the development of an if statement, which allows the program to execute a block of code in multiple blocks of code based on the result of an expression, which can only be of an ordered type variable as a condition factor, and the other, such as a string, is not feasible.
| 1234567891011121314 |
var I: Integer;begin caseI of 1: { 如果 I = 1} DoSomething1; 2, 3: { 如果 I = 2或者3,相当于if I in [2, 3]} DoSomething2; 4..10: { 如果 I在4到10范围内(含4和10)} DoSomething3; else{ 如果是其他条件,通常用来实现默认处理,else块也不是必须的} DoSomething; end;end; |
Conditional branch of Program Flow control (Delphi)