Jump to content
Sign in to follow this  
357mag

How many end keywords are there?

Recommended Posts

I thought in Delphi there was end; with a semicolon

 

And end. with a period

 

But I have seen a third end

 

That one has nothing after the keyword

 

What's going on?

Share this post


Link to post
10 minutes ago, 357mag said:

But I have seen a third end

 

That one has nothing after the keyword

The semicolon is optional after an end in some circumstances. Please see this. I know it's not after an "end" but the principle is still the same.

Edited by Dave Nottage

Share this post


Link to post
49 minutes ago, Dave Nottage said:

The semicolon is optional after an end in some circumstances.

Semicolon is also forbidden before else...

Share this post


Link to post

Semicolon is the statement separator, and so is only needed if the next code is a statement

 

It's also only by convention that you put the semicolon right next to the end. You could equally write:

 

begin
  // foo
end                  ;

 

Same is true for the end of a unit. You can write it like this:

 

end               .

 

If you omit the period at the end of a unit the compiler error says

 

Quote

[dcc32 Error]: E2029 '.' expected but end of file found

 

So, it's talking about the period which it considers a separate thing.

 

So, in conclusion, there's only one end keyword. And semicolon is the statement separator, unrelated to end. And the period marks the end of a unit. Again unrelated to the end keyword.

Edited by David Heffernan

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×