Which loop is more efficient?
#1

This
pawn Код:
for ( new index = 0; index != MAX_PLAYERS; ++ index )
Or this
pawn Код:
for ( new index = 0; index < MAX_PLAYERS; index ++ )
P.S. state your reason as-well.
Reply
#2

I don't think it matters. Have you tested it? Pre- or post-incremention of the variable has also no effect on the statements in the loop.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
I don't think it matters. Have you tested it? Pre- or post-incremention of the variable has also no effect on the statements in the loop.
The result is same. But I still want to know what to use.
Reply
#4

If it's the same, I'd use...

pawn Код:
for ( new index = 0; index < MAX_PLAYERS; index ++ )
... because it's easier to understand.
Reply
#5

SECOND one indeed. if you (accidently) set the index to >MAX_PLAYERS, the loop could be infinite.
sry i've read them too fast. major fail. oops
counting from a minimum (0) to a max(500) always should exclude the chance to get larger values like 501. the != check accepts both. the < only accepts the 0-499 boundary
Reply
#6

Quote:
Originally Posted by Babul
Посмотреть сообщение
first one indeed. if you (accidently) set the index to >MAX_PLAYERS, the loop could be infinite.
Yep. Thanks bud

Edit: Another big thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)