confused about syntax - where does procedure end where to place " ; " ? 
Author Message
 confused about syntax - where does procedure end where to place " ; " ?

Hello,

if got a question to the use of semicolon, if-else and procedures.

If got Pascal code to port and i am unsure about the the end and
beginning of code statements. So i placed some relevant part in the
example and put my questions in comments.

Thanks a lot in advance:

Best regards

Tom

Here the code i am dealing with:

procedure CalculateFortyTwo

begin                                   {* begin of procedure *}
   Hitchhiker := Highway * Norway;
   if Hyperspeed > 1000
    then
     begin
        moreStuff := important + minorImportant;
        moreStuff2 := important2 + minorImportant2;
     end
   else
     begin
        doNotDestroy := galaxyHighway + milkyWay;

        {*
    a) Isn't there an "end" missing at this place ?
        *}
     end;
        {*
    b) Is this the end of the procedure - or just the end of the
       if-else-part ?          
    c) Is this a new if-else or still part of the former else branch
        *}

    if foo = 0 AND bar = 0 then
          alpha := gamma*2
        else
          alpha := beta*2;
        {*
    d) I guess "alpha:=beta*2;" ends "if foo=0" or am i mistaken?
        *}

    if foba > 2 then
        begin
          ... ;
         end
     else
        begin
         enron := bigLoss*3;
        end;

        {*
    d) Is this end; the END of the foba >2 ?
        *}

Thanks again.



Mon, 30 May 2005 23:41:37 GMT  
 confused about syntax - where does procedure end where to place " ; " ?
I have inserted comments below
For an attempted clarity I prefix all my entries with =

Quote:

> Hello,

> if got a question to the use of semicolon, if-else and procedures.

> If got pascal code to port and i am unsure about the the end and
> beginning of code statements. So i placed some relevant part in the
> example and put my questions in comments.

> Thanks a lot in advance:

> Best regards

> Tom

> Here the code i am dealing with:

> procedure CalculateFortyTwo

= missing semicolon after procedurename.

- Show quoted text -

Quote:

> begin {* begin of procedure *}
>    Hitchhiker := Highway * Norway;
>    if Hyperspeed > 1000
>     then
>      begin
> moreStuff := important + minorImportant;
> moreStuff2 := important2 + minorImportant2;
>      end
>    else
>      begin
>         doNotDestroy := galaxyHighway + milkyWay;

> {*
>     a) Isn't there an "end" missing at this place ?
> *}
>      end;
> {*
>     b) Is this the end of the procedure - or just the end of the
>        if-else-part ?

= This end refers to the last previous begin, 2 lines up,
 that is it just ends the if-then-else..

Quote:
>     c) Is this a new if-else or still part of the former else branch
> *}

= The following if initiates a new if - then - else clause

Quote:
>     if foo = 0 AND bar = 0 then
>   alpha := gamma*2
> else
>   alpha := beta*2;
> {*
>     d) I guess "alpha:=beta*2;" ends "if foo=0" or am i mistaken?

= True

Quote:
> *}

>     if foba > 2 then
> begin
>     ... ;
>          end
>      else
>         begin
> enron := bigLoss*3;
>         end;

> {*
>     d) Is this end; the END of the foba >2 ?

= Yes

Quote:
> *}

= In case you have overlooked it: You seem to be missing an end;
at the end of your procedure. Remember that every "begin"
requires a matching "end"

regards Sven

- Show quoted text -

Quote:

> Thanks again.



Wed, 01 Jun 2005 02:59:41 GMT  
 confused about syntax - where does procedure end where to place " ; " ?


Wed, 18 Jun 1902 08:00:00 GMT  
 confused about syntax - where does procedure end where to place " ; " ?

Quote:

>Hello,

>if got a question to the use of semicolon, if-else and procedures.

>If got pascal code to port and i am unsure about the the end and
>beginning of code statements. So i placed some relevant part in the
>example and put my questions in comments.

Well, "porting" Pascal code without knowledge of Pascal basics is a
bit hard...

Quote:

>procedure CalculateFortyTwo;

You are missing a semicolon at the end of this statement....
Quote:

>begin                                       {* begin of procedure *}
>   Hitchhiker := Highway * Norway;
>   if Hyperspeed > 1000
>    then
>     begin
>    moreStuff := important + minorImportant;
>    moreStuff2 := important2 + minorImportant2;
>     end
>   else
>     begin
>        doNotDestroy := galaxyHighway + milkyWay;

>    {*
>    a) Isn't there an "end" missing at this place ?
Why?
>    *}
>     end;
>    {*
>    b) Is this the end of the procedure - or just the end of the
>       if-else-part ?      

of course it ends the if-then-else statement....

Quote:
>    c) Is this a new if-else or still part of the former else branch
>    *}

Yes, it's a new if-then-else statement...

Quote:
>    if foo = 0 AND bar = 0 then
>      alpha := gamma*2
>    else
>      alpha := beta*2;
>    {*
>    d) I guess "alpha:=beta*2;" ends "if foo=0" or am i mistaken?
>    *}

Yes you are mistaken, you have another if-then-else statement.

Three  things to remember:
- if you have only a single expression after a if-decision (either
then or lese), you do not need to put a begin-end around it...
- as a semicolon ends a complete statement, so if you have an else
branch there is NO semicolon at the end of the last exprssion/staement
of the then-branch
- else is a part of an if-then-else statement, it cannot start a new
statement...

Quote:

>    if foba > 2 then
>    begin
>      ... ;
>         end
>     else
>        begin
>     enron := bigLoss*3;
>        end;

>    {*
>    d) Is this end; the END of the foba >2 ?
>    *}

yes, it closes the else brnach if the if-then-else statement...

sorry if teh description is a bit rough, i am a programmer not a
teacher.... ;-))

Ralf



Wed, 01 Jun 2005 04:34:20 GMT  
 confused about syntax - where does procedure end where to place " ; " ?


Wed, 18 Jun 1902 08:00:00 GMT  
 confused about syntax - where does procedure end where to place " ; " ?

Quote:
> if got a question to the use of semicolon, if-else and procedures.
> If got pascal code to port and i am unsure about the the end and
> beginning of code statements. So i placed some relevant part in the
> example and put my questions in comments.

   There is a simple and unambiguous rule about the Pascal semicolon:
it's a _statement_separator_.  Thus, it's needed _ONLY_ when separating 2
Pascal _statements_, and it isn't needed (or used for any real purpose)
when only _terminating_ a statement (as required by some other languages,
such as C/C++).
   This principle/rule is demonstrated in the following ways:

begin
  statement1;
  statement2;
  statement3
end

  if condition then
    statement1 { ; cannot be used here because...}
  else  { "else" is not the start of a Pascal statement! }
    begin
      statement2;
      statement3;
      statement4
    end

  repeat
    statement1;
    statement2
  until condition { "until" is not the start of a Pascal statement! }

   So, knowing that comprises a Pascal statement is key to knowing where
to use the statement separator (the semicolon)...and where it's not
needed.



Thu, 02 Jun 2005 13:08:54 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. "Confused" TDataSource

2. The keys "-"/"+"/"*"

3. "At beginning/end of table"

4. "Syntax Error in expression" strange error

5. HELP : "Invalid Paramater", when doing Tquery.Open, seems to not release resources

6. ""256 Color Mouse""

7. I need help with "procedure"

8. I need help with "procedure"

9. "Backup/restore" and "save" procedures for delphi/paradox

10. What are "Denormals" and "Nans"

11. Utility to convert "asm" to "inline( )"

12. "delete from" followed by "insert into" = AV

 

 
Powered by phpBB® Forum Software