Continue seems to work like break


#1

Hey,
I started playing with code combat yesterday and I think it is pretty cool. While solving Gridmancer, I used continue in my javascript. It took me a while to realize that it wasn’t behaving as expected. It seems like it is doing a break instead.
Here is some sample code for Gridmancer that illustrates what I mean. The code below should fill up the map with alternating (checkered) squares but instead it stops after the first.

var grid = this.getNavGrid().grid;
var tileSize = 4;
for(var y = 0; y + tileSize < grid.length; y += tileSize) {
    for(var x = 0; x + tileSize < grid[0].length; x += tileSize) {
        if (((x+y)/4)%2 == 0) continue;
        var occupied = grid[y][x].length > 0;
        if(!occupied) {
            this.addRect(x + tileSize / 2, y + tileSize / 2, tileSize, tileSize);
            this.wait();  // Hover over the timeline to help debug!
        }
    }
}

And below I have equivalent code that doesn’t use continue which works perfectly.

var grid = this.getNavGrid().grid;
var tileSize = 4;
for(var y = 0; y + tileSize < grid.length; y += tileSize) {
    for(var x = 0; x + tileSize < grid[0].length; x += tileSize) {
        if (((x+y)/4)%2 != 0) {
            var occupied = grid[y][x].length > 0;
            if(!occupied) {
                this.addRect(x + tileSize / 2, y + tileSize / 2, tileSize, tileSize);
                this.wait();  // Hover over the timeline to help debug!
            }
        }
    }
}

I hope this is helpful


#2

Ah, I know what you mean: the continue stuff is getting mangled between JS_WALA and traceur in our Aether transpiler. It sounds like it might be a bit hairy to fix: https://github.com/google/traceur-compiler/issues/605

I’ll start an issue in our GitHub to see if we can’t work around it a better way.