Make cikle back.
#1

Hi,

I want to make cikle when variable is

new DDDRRRUUNNNN[ 20 ];


I want to make cikle from 19 to 0,

Код:
for(new i = 19; i == 0; i --)
But this is not working.
Reply
#2

for(new i = 19; i == 0; i --)

what you're doing is:

for( new i = 19; //the variable i has now an integer value of 19;
i == 0; // checking if i is equal to 0, which it isn't because it's 19.
i-- // if i is equal to 0, lower the value with 1.

this will never work, as the variable i, is 19, and it ain't 0, so this will create a never ending loop, because i is always 19, and will never decrease as it only decreases when it's 0.

try this instead:

for( new i = 19; i > 0; i-- )

that checks if i is still above 0, if it is, it'll continue, else it'll stop.
Reply
#3

That would loop 19 times (19 to 1), but he wants 20 (19 to 0). So it should be:
pawn Код:
for (new i = 19; i >= 0; --i)
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
That would loop 19 times (19 to 1), but he wants 20 (19 to 0). So it should be:
pawn Код:
for (new i = 19; i >= 0; --i)
oh, yea, you're right.

thanks for pointing that out
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)