I.T. Discussion Community!
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesDelphi  Print This     

If Statement (Delphi and C++ Cross Reference Guide)

By Mike Prestwood

Delphi versus C++: A side by side comparison between Delphi and C++.


Common statements such as if statements, loops, etc.

If Statement

[Other Languages] 
Delphi:   If..Else If..Else

Notice in the more complete example that the semicolon for the begin..end block after end is not included. That tells the compiler something else is coming (the statement is not finished). Also note the semicolon is missing right before the final "else" statement.

Note: The following example uses floating point literals. In Delphi, to specify a fractional floating point literal between 1 and -1, you preceed the decimal with a 0; otherwise, you will get a compiler error (i.e. .1 + .1 does not work).

Syntax Example:
if (0.1 + 0.1 + 0.1) = 0.3 then
  ShowMessage('Not correct');
//Complete example:
if x = true then
  ShowMessage('x is true');
Else If y = 'Mike' Then 
  ShowMessage('hello mike')
  ShowMessage('last option');
C++:   if..else if..else

Same as standard C.

Syntax Example:
//C++Builder example using the VCL ShowMessage.
int x;
x = 8;
if (x == 10) {
ShowMessage("x is 10.");
} else if (x < 10) {
ShowMessage("x is less than 10.");
} else {
ShowMessage("x must be greater than 10.");

Follow PrestwoodBoards on: 

©1995-2021 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech