05.10.2011, 10:52
Ill try to explain you with very easy words what you did wrong.
For example we have this code.
This will return:
In this case, pawn will first check if our number is higher or equal than 0, which is true since 5 >= 0, and it will SKIP all other checks.
In a second example we have
This will return:
In this case, pawn will check our number with all 6 if() statements, and it will not skip anything. (Which is still not what you want)
BUT!
This will return:
In this case, it will first check our number with 4 >= 5, which is false, it will then try 4 >= 4, which is true, and it will SKIP all others...
Which is exactly what you need
For example we have this code.
pawn Код:
new num = 4;
if (num >= 0) print("Our number is higher or equal to 0");
else if (num >= 1) print("Our number is higher or equal to 1");
else if (num >= 2) print("Our number is higher or equal to 2");
else if (num >= 3) print("Our number is higher or equal to 3");
else if (num >= 4) print("Our number is higher or equal to 4");
else if (num >= 5) print("Our number is higher or equal to 5");
Код:
Our number is higher or equal to 0
In a second example we have
pawn Код:
new num = 4;
if (num >= 0) print("Our number is higher or equal to 0");
if (num >= 1) print("Our number is higher or equal to 1");
if (num >= 2) print("Our number is higher or equal to 2");
if (num >= 3) print("Our number is higher or equal to 3");
if (num >= 4) print("Our number is higher or equal to 4");
if (num >= 5) print("Our number is higher or equal to 5");
Код:
Our number is higher or equal to 0 Our number is higher or equal to 1 Our number is higher or equal to 2 Our number is higher or equal to 3 Our number is higher or equal to 4
BUT!
pawn Код:
new num = 4;
if (num >= 5) print("Our number is higher or equal to 5");
else if (num >= 4) print("Our number is higher or equal to 4");
else if (num >= 3) print("Our number is higher or equal to 3");
else if (num >= 2) print("Our number is higher or equal to 2");
else if (num >= 1) print("Our number is higher or equal to 1");
else if (num >= 0) print("Our number is higher or equal to 0");
Код:
Our number is higher or equal to 4
Which is exactly what you need