Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

If statement question

Hi All,

I've a very simple question about Delphi IF statement. Now I really get confused about the semicolon (;) and the Begin End blocks. As of the (;) in Delphi IF statements I need to understand when to put them and when not to put them.
As of the Begin - End blocks, when shall I add code under Begin-End block and when not.

So I will appreciate it so much if someone can please explain those two issues to me.

**** NO links to tutorials or help files ****
0
GiantMatrix
Asked:
GiantMatrix
  • 3
  • 2
1 Solution
 
Harisha M GCommented:
Hi, there are two forms:

1       if Condition then Statement;
2       if Condition then Statement else Statement;

You should NOT put the semicolon BEFORE the ELSE statement.

If you have more than one line of code to be put inside the IF or ELSE block, then use BEGIN and END blocks. Otherwise, it is unnecessary

This page has examples that clarify your doubts:
http://www.delphibasics.co.uk/RTL.asp?Name=If

Also see the description: Delphi insists on no ';' after the then statement if an else statement follows.

---
Harish
0
 
GiantMatrixAuthor Commented:
Hi Harish,

What if I have a Begin End block inside the IF or Else If, can you please give me an example for this?

I've visited the link you provided here although I already know it and it does not include an answer to my previous question...actually that is why I said **** NO links to tutorials or help files ****.

Anyway, can you please give me an example for IF - ELSE IF - ELSE statement with (begin end) inside the else if and if.

Thanks in advance!
0
 
Harisha M GCommented:
IF condition THEN
    BEGIN
        statement1;
        statement2;
    END                                             (* No semicolon since ELSE block is present*)
ELSE
    BEGIN
        statement3;
        statement4;
    END;

0
 
Harisha M GCommented:
IF condition1 THEN
    BEGIN
        statement1;
        statement2;
    END                     (* No semicolon since ELSE block is present *)
ELSE IF condition2 THEN
    BEGIN
        statement3;
        statement4;
    END                     (* No semicolon since ELSE block is present *)
ELSE
    BEGIN
        statement5;
        statement6;
    END;

0
 
GiantMatrixAuthor Commented:
Hi Harish,

Thank you so much for your outstanding help and support :-)

Thanks in advance!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now