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 ****
GiantMatrixAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harisha M GEngineerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 GEngineerCommented:
IF condition THEN
    BEGIN
        statement1;
        statement2;
    END                                             (* No semicolon since ELSE block is present*)
ELSE
    BEGIN
        statement3;
        statement4;
    END;

0
Harisha M GEngineerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.