Jump to content
Sign in to follow this  
John Kouraklis

Difference between Pred and -1

Recommended Posts

Hi,

I am looking at some older code and I see the author uses the following statement:

 

for i:=0 to Pred(WhateverList.count) do

 

instead of the usual one:

 

for i:=0 to WhateverList.count - 1 do

 

Does it make any real difference or it's just a personal preference?

 

Thanks

Share this post


Link to post

In that code statement it does not matter if Pred() or attached -1 will be used. Both do same but Pred() can do more than give back decremented number.

 

Those types are supported:

Characters, Non-floating number types, Enumeration types and Pointers 

 

Example:

Character := Pred( Char( 'X' ) ); = W

 

/edit

It might be possible that on mass operations a -1 is faster than using Pred().

Not tested by myself but possible.

(not for above example, when used inside loops)

Edited by KodeZwerg

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  

×