header image
Home arrow Programming arrow Decision making (IF & Case)
Decision making (IF & Case) PDF Print E-mail
Written by JAK Olivier   
Jun 28, 2009 at 09:24 AM

Decision making in Delphi is determined using IF and CASE statements. Below are some examples of coding frameworks:

Basic IF statement

IF <condition(s)> THEN
BEGIN
  <statements>
END;

IF Statement with an ELSE

IF <condition(s)> THEN
BEGIN
  <statements>
END
ELSE {If the top condition is not met then...}
BEGIN
  <statements>
END;

IF <condition(s)> THEN
BEGIN
  <statements>
END
ELSE
IF <condition(s)> THEN
BEGIN
  <statements>
END
ELSE {If the top conditions are not met then…}
BEGIN
  <statements>
END;

Additional logical operators can also be added: AND, OR, NOT (use brackets around conditions)


CASE statement

CASE <selection statement> OF
  <value1> := <statement(s)>;
  <value2> := <statement(s)>;
  <value3> := <statement(s)>;
ELSE
<statement(s)>
END;

Last Updated ( Jun 28, 2009 at 07:39 AM )
Statistics
Members: 2
News: 41
Web Links: 4
Visitors: 200725