Author Topic: While loops  (Read 1020 times)

I don't get how to use them, I use them and game goes boom because of infinite loop.

Is it like the do function in C++?

Code: [Select]
do{
 //stuff
while(fred != bob);

Because that's how I've been using it without the do bit like:

Code: [Select]
while(%fred != 1){
 //stuff
}

Yeah, while() loops must be used very carefully.  They're really only useful when you absolutely know that your while will terminate soon after the call.

It's better to use a for() loop.  Here's an example of a for() loop used in place of a while() loop:

Code: [Select]
%client.hasThisProperty = 1;

while(%client.hasThisProperty)
{
     //do stuff here
}

Code: [Select]
%client.hasThisProperty = 1;

for(%i = %client.hasThisProperty;%i >= 1;%i = %client.hasThisProperty)
{
     //do stuff here
}

I shall try that, thanks.