You can't use a
boolean
in a for loop. You're effectively doing this:
for d = 0 to false (or true)
...
Next, you're incrementing the control variable
d
inside the loop - this goes WAY beyond bad programming practice.
Finally, we can't help you convert it if we don't know the types of the variables being use.