In this article I will share About Looping and Branching in Delphi 7.
Looping is repeating one or a set of commands to achieve certain conditions.
Branching is one of the control structure that allows the selection of the command to be executed.
Looping Statements in Delphi 7 :
1. For To Do
This loop runs by using a counter variable that will be added automatically when a command has been completed. The general form of this loop :
For counter: = value end of the initial value To Do
Begin
command;
command;
end;
2. For downto Do
The loop is the same as using a For loop with a To Do, but reduced the content of the counter (back / down).
The general form of this loop is:
For counter: = begin value downto end value Do
Begin
command;
command;
end;
3. Repeat Until
The loop is working until the desired condition is reached. This loop can be used as a loop that uses a lot of conditions (multi-loop condition).
The general form:
repeat
command;
command;
Until conditions;
4. Do While
The loop is similar to Repeat Until but the checking prosses run before performing an iterative process. This loop runs as long as the value condition are true. If the condition has false value then the loop will stop.
Do while general form :
While conditions do
Begin
command;
command;
end;
Branching Statements in Delphi :
1. If ... Then ... Else
A command that serves to make decisions on some condition. Branching form is often used for conditions that are not too many.The selection of a conditional used only to perform an action when the condition of the command syntax are true. Bentuk conditional is:
if then
Begin
... {action-1}
end;
2. IF ... THEN ... ELSE: Selection of two cases
If ... then ... else is generally used to perform simple bifurcation (between 2 or 3 branches). Or for a lot of branching, which is the prerequisite conditions involving more than one parameter. Conditional form of the command syntax is:
if then
Begin
... {action-1}
end
else
Begin
... {action}-2
end;
IF ... THEN ... ELSE: Selection of N cases
if then
Begin
... {action-1}
end
If then else
Begin
... {action}-2
end
else
Begin
... {action}-3
end;