Small question...
#1

When doing something like this:
pawn Код:
for(new i = 0; i < BLAH; i++)
Does it make a difference if you do this:
pawn Код:
for(new i = 0; i < BLAH; ++i)
Reply
#2

The first one is wrong, the last one is the working one..
Reply
#3

Quote:
Originally Posted by Drake_Lopez
Посмотреть сообщение
The first one is wrong, the last one is the working one..
Incorrect. Because I've always used 'i++' and it works fine. I just recently saw someone use ++i and didn't know if it made a difference.
Reply
#4

Here's the results:

Код:
[21:46:20]  Increase of i++ 0 using <
[21:46:20]  Increase of i++ 1 using <
[21:46:20]  Increase of i++ 2 using <
[21:46:20]  Increase of i++ 3 using <
[21:46:20]  Increase of i++ 4 using <
[21:46:20]  Increase of ++i 0 using <
[21:46:20]  Increase of ++i 1 using <
[21:46:20]  Increase of ++i 2 using <
[21:46:20]  Increase of ++i 3 using <
[21:46:20]  Increase of ++i 4 using <
[21:46:20]  Increase of ++i 0 using !=
[21:46:20]  Increase of ++i 1 using !=
[21:46:20]  Increase of ++i 2 using !=
[21:46:20]  Increase of ++i 3 using !=
[21:46:20]  Increase of ++i 4 using !=
[21:46:20]  Increase of i++ 0 using !=
[21:46:20]  Increase of i++ 1 using !=
[21:46:20]  Increase of i++ 2 using !=
[21:46:20]  Increase of i++ 3 using !=
[21:46:20]  Increase of i++ 4 using !=
using

pawn Код:
main()
{
    for(new i = 0; i < 5; i++) printf(" Increase of i++ %d using <", i);
    for(new i = 0; i < 5; ++i) printf(" Increase of ++i %d using <", i);
    for(new i = 0; i != 5; ++i) printf(" Increase of ++i %d using !=", i);
    for(new i = 0; i != 5; i++) printf(" Increase of i++ %d using !=", i);
    for(new i = 0; i > 5; i++) printf(" Increase of i++ %d using  >", i);
    for(new i = 0; i > 5; ++i) printf(" Increase of ++i %d using  >", i);
}
I saw a topic where ****** said that makes no difference in PAWN but he does
Код:
for(new i = 0; i != 5; ++i)
because in C++ is faster.

Edit: That was an example, I know that I've assigned the wrong variable its acctualy int in C
Reply
#5

Either version works in for loops. There's no difference whatsoever. The difference becomes clear when you start using this in other structures. For example:
pawn Код:
new i = 1;
printf("%d", someArray[++i]);
Will access index 2. i is incremented first.

pawn Код:
new i = 1;
printf("%d", someArray[i++]);
Will access index 1. i is incremented afterwards.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)