Testing Conditions

This section compares if and case constructs in Pascal to similar constructs in C and Visual Basic. We assume that you've used these types of programmatic constructs before, so we don't spend time explaining them to you.

The if Statement

An if statement enables you to determine whether certain conditions are met before executing a particular block of code. As an example, here's an if statement in Pascal, followed by equivalent definitions in C and Visual Basic:

{ Pascal }
if x = 4 then y := x;

/* C */
if (x == 4) y = x;

'Visual Basic
If x = 4 Then y = x

Note

If you have an if statement that makes multiple comparisons, make sure that you enclose each set of comparisons in parentheses for code clarity. Do this:

 if (x = 7) ...

Get Borland® Delphi™ 6 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.