I'm setting up a hex grid. The column/row system I use puts 0, 0 as the top left corner, and increasing columns (x) moves to the right but also vertically upwards. So columns run straight up and down, but rows run to the right but slanted upwards a bit.
This code...
for (j = 0; j < bd*2-1; j += 1) // bd is "board dimension", in my case 9
{
for (i = 0; i < bd*2-1 and i < j+bd; i += 1)
{
if (i <= j-bd)
continue;
scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs); // bxo and byo are arbitrary board x/y origins where the first cell is drawn, hs, hh, and vs are the gaps between cells in horizontal and vertical directions.
}
}
produced this:
which is exactly what I want, a large hexagon with 9 smaller hexagons on each side.
So I thought I would be sophisticated and move that continue condition into the for loop. I wrote this...
for (j = 0; j < bd*2-1; j += 1)
{
for (i = 0; i < bd*2-1 and i < j+bd and i > j-bd; i += 1) // added "i > j-bd", basically migrated the condition into this inner loop
{
//if (i <= j-bd)
//continue;
scr_ini_hex(i, j, bxo + i*hs, byo + j*hh - i*vs);
}
}
and it produced this:
What went wrong here? I thought they were logically equivalent (except negating the condition, because the continue code was like a do until, but the for condition is like a do while).