The End If is optional if you put your code on a single line.
//Single line example.
If X = True Then Response.Write "hello"
//Complete example.
If X = True Then '>>>do something.
ElseIf Y = "ABC" Then '>>>do something.Else '>>>do something.
End If
If X = True Then MsgBox "hello"
Use () around evaluation with no "then".
Boolean x = true;
if (x){ MessageBox.Show("hello");}else if (x==false){ MessageBox.Show("goodbye");}
else
{
MessageBox.Show("what?");}
Same as standard C.
//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.");}
if (x == 10) { MessageBox::Show("x is 10");} else if (x < 10) { MessageBox::Show("x is less than 10"); } else { MessageBox::Show("x must be greater than 10"); }
ObjectPAL supports a simple If...Else...EndIf statement.
Notice ObjectPAL does not support an ElseIf feature as part of an if statement. Instead use a switch statement
'Does ObjectPAL evaluate the math correctly? No!
If (.1 + .1 + .1) = .3 Then msgInfo("", "Correct")Else msgInfo("", "Not correct")EndIf
'Switch statement example.switch case x = "Nate": MsgInfo("", "Hi Nate") case x = "Felicia": MsgInfo("", "Hi Felly")
otherwise: MsgInfo("", "Who are you?")
endSwitch
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).
if (0.1 + 0.1 + 0.1) = 0.3 then ShowMessage('Correct')else ShowMessage('Not correct');
//Complete example:if x = true thenbegin
ShowMessage('x is true');
end
Else If y = 'Mike' Then
ShowMessage('hello mike')
Else
ShowMessage('last option');
//Complete example:if x = true then begin
Syntax template:
if (expression) {
expression1_true_code;
} else if (expression2) {
expression2_true_code;
} else {
otherwise_code;
}
if ((.1 + .1 + .1) == 0.3) { System.out.println("Correct");} else { System.out.println("Not correct");}
Same as C/C++ but, as usual, the semicolons are optional.
var x = 8;
if (x == 10) { document.write("x is 10.");} else if (x < 10) { document.write("x is less than 10."); } else { document.write("x must be greater than 10."); }
Notice Perl is different from most other languages in it's spelling of elsif (else is not spelled correctly).
$x = 8;
if ($x == 10) { print "X is 10.";} elsif ($x < 10) { print "X is less than 10.";} else { print "X must be greater than 10.";}
The PHP if statement consists of using if, elseif, and else.
if ($x == 10) { echo "x is 10."; } elseif ($x < 10) { echo "x is less than 10.";} else { echo "x must be greater than 10."; };
ElseIf Y = "ABC" Then MsgBox "goodbye"Else MsgBox "what?"End If
Same as VB classic.
If x Then MessageBox.Show("hello")ElseIf Not x Then MessageBox.Show("goodbye")Else MessageBox.Show("what?")End If