Difference between Do While & while

CrazyJosh1

Active Member
Other than the obvious text, what is the difference between the "Do/While" and "While" coding?

ie:

Code:
do
{
   xxx
}
while yyy
and
Code:
while yyy
{
  xxxx
}
as far as I can tell, they should both do the same thing, but they do act differently. ie: sometimes "while" doesn't work as well as "Do/while" any reason behind this that I am missing?
 

Shaba

Active Member
The first option will execute once, even if not yyy

The second option will never execute if not yyy
 

CrazyJosh1

Active Member
Shaba said:
The first option will execute once, even if not yyy

The second option will never execute if not yyy
hmmmmmmmmmm
do you know why
Code:
			Me.Ability["Necropsy"]:Use
			wait 1
			while ${Me.IsCasting}
			{
				if (!${Me.Target(exists)})
				{
					Pawn[ID,${curTargetID}]:Target
				}
				wait 1
			}
doesn't wait, while its casting but
Code:
			Me.Ability["Necropsy"]:Use
			wait 1
			do
			{
				if (!${Me.Target(exists)})
				{
					Pawn[ID,${curTargetID}]:Target
				}
				wait 1
			}
			while ${Me.IsCasting}
Does.
 

Shaba

Active Member
Not really, unless the first option just needs more than a wait 1 before the loop. Personally, I would just do
Code:
wait 30 !${Me.IsCasting}
but I'm not sure what you are doing with the target condition
 

Cr4zyb4rd

Active Member
To be a bit more explicit, it takes a small-yet-non-zero amount of time for IsCasting to report true once you cast a spell, probably somewhere on the order of .1 to .3 or so seconds. In the do/while case, the loop runs through the first time before evaluating the "while" condition, and that little bit of extra processing is probably just long enough for the client to update.

As shaba indicated, you're probably better off just doing something like
Code:
Me.Ability["Necropsy"]:Use
; wait half a second to let the spell start casting
wait 5
; that should do it...now wait 10 seconds or until IsCasting is false, whichever comes first
wait 100 !${Me.IsCasting}
 

spudman

Active Member
and if you wanted it to continue 'as soon as' it properly updates Me.IsCasting, then you could do...
Code:
Me.Ability["Necropsy"]:Use
; wait until Me.IsCasting properly updated but not more than half a second
wait 5 ${Me.IsCasting}
; ...
wait 100 !${Me.IsCasting}
 
Top Bottom