Last active
August 29, 2015 13:57
-
-
Save julsam/9502207 to your computer and use it in GitHub Desktop.
breaking nested loop in haxe - which solution is the best ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canPlace = 1; | |
for (y in 0...height) | |
{ | |
for (x in 0...width) | |
{ | |
if (mapArr[x][y] != ' ') | |
{ | |
canPlace = 2; | |
break; | |
} | |
} | |
if (canPlace == 2) break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canPlace = 1; | |
for (y in 0...height) | |
{ | |
for (x in 0...width) | |
{ | |
if (mapArr[x][y] != ' ') | |
{ | |
canPlace = 2; | |
// we want to break here ! but we can't because of the nested loop ! and there is no goto in haxe :( | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canPlace = 1; | |
(function() { // self invoking local function | |
for (y in 0...height) | |
{ | |
for (x in 0...width) | |
{ | |
if (mapArr[x][y] != ' ') | |
{ | |
canPlace = 2; | |
return; | |
} | |
} | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canPlace = 1; | |
for (y in 0...height) | |
{ | |
for (x in 0...width) | |
{ | |
if (mapArr[x][y] != ' ') | |
{ | |
canPlace = 2; | |
y = height; // cause the outer loop to break | |
break; // break the inner loop | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canPlace = 1; | |
var exitedInner:Bool = false; | |
for (y in 0...height) | |
{ | |
for (x in 0...width) | |
{ | |
if (mapArr[x][y] != ' ') | |
{ | |
canPlace = 2; | |
exitedInner = true; | |
break; | |
} | |
} | |
if (exitedInner) break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canPlace = 1; | |
var y = [for (i in 0...height) i]; | |
Lambda.foreach(a, function(y) { | |
for (x in 0...width) | |
{ | |
if (mapArr[x][y] != ' ') | |
{ | |
canPlace = 2; | |
return false; | |
} | |
} | |
return true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment