Fixed array comparison logic in for loops