for (y = 1; y <= Bottom; y++) { next = 1; for (x = 1; x <= Right; x++) { if ([x,y] != "") { if (x > next) { [next,y] = [x,y]; [x,y] = ""; } next++; } } }