javascript to actionScript 3

hello
i am try to create crossWord generator and i have javascript sourc code but i have encountered problem
i want to convert this code to as3

for(var r = row + 1, c = col, i = 0; r < grid.length && c < col + word.length; c++, i++){
var is_empty = grid[r][c] == null;
var is_intersection = grid[row][c] != null && grid[row][c][‘char’] == word.charAt(i);
var can_place_here = is_empty || is_intersection;
if(!can_place_here) return false;
}

// check to make sure we aren’t overlapping a char (that doesn’t match)
// and get the count of intersections
for(var c = col, i = 0; c < col + word.length; c++, i++){
var result = canPlaceCharAt(word.charAt(i), row, c);
if(result === false) return false;
intersections += result;
}
sorry for my bad english

Can you post what you have tried? JS and AS have a lot of similarities :slight_smile:

thank you
my problem is solved. i just copy and paste the code
i just cant understand the for loop with multipleVariables

Ignore the fact that the for loop has multiple variables. It is just an expression that evaluates to a number. This…

for (var i = 0; i < 10; i++) {

}

…is similar to this…

var foo = 3;
var bar = 7;

for (var i = 0; i < foo + bar; i++) {

}

:stuck_out_tongue:

1 Like

I’ve never seen that either.(or maybe I forgot it?)
Its a bit more involved than just a single loop. Its possible to make a nested loop with just a single for loop for example.

I think it was interesting. Like this for example…

for (var i = 0,j = 0; i < 4 && j < 4; i++) {
	if (i % 4 == 0) {
		i=0;
		j++;
	}
	trace(i + " " + j);
}

well, an if instead of a for, but anyway :smiley:

There’s not a lot that can’t go within the initializer of a loop. E.g. (this is JS, but you get the idea):

for(new class _ { constructor(){ Array.of(1,2,3).map(e => console.log(e)) } }; setTimeout(4) < 1500;) 0
1 Like

well, actually, hmm… I’m not sure what that does :slight_smile: