- Home /
for loop not working if I start at the end number.
So I have this for loop
public var Directions : boolean[];
for (var U : int = 9; U >= 9 && U ]
but when !Directions[11] or !Directions[10, 11] it doesn't do the loop, but lets say !Directions[9] or !Directions[9, 10] or !Directions[9, 10, 11] it works.
I think the problem is that it reads 9 first and if that is falls it stops there, but I need it to go through the full loop, not just the first one.
so I am checking a boolean aray, to see if the booleans 9-11 are false, but if lets say 9 is true but 10 and 11 are false, it will stop at 9, and not do the loop for 10 and 11.
Try moving !Directions[U] in the loop (not in the actual statement) and use "continue;". Increment by i++ for every one found and print the i outside of the loop to see how many were found.
Answer by maccabbe · Mar 29, 2015 at 01:28 AM
If you want to go from 9 to 11 and not halt the for loop due to a condition such as !Direction[U] then don't use the condition as a condition for the for loop. Instead use it as a condition for an if statement inside the for loop i.e.
for (var U : int = 9; U >= 9 && U <= 11; U++){
if(!Directions[U]){
// code here
}
}
Your answer
