在我的代碼中,我有一個嵌套循環,它不會迭代if語句的異常,該語句總是無論發生什麼情況都會發生。如果沒有if語句,循環迭代循環的部分代碼變得無法訪問。無論我嘗試過什麼,我都無法獲得內部循環來迭代。嵌套循環沒有迭代
class Map
{
public int Width { get; set; }
public int Height { get; set; }
public Vector2[] positions = new Vector2[500*500];
private GroundVoxel[,] map = new GroundVoxel[500, 500];
private Vector2 voxelPosition = new Vector2(0,0);
private static int sizeX = 499, sizeY = 499, airLevel = 425;
private int positionX = 0, positionY = 0, vectorNumber = 0;
public Map()
{
}
public Vector2[] Initialize()
{
for (int i = 0; i <= sizeY; i++)
{
for (int j = 0; j <= sizeX; j++) <-- This does not iterate.
{
map[positionX, positionY] = new GroundVoxel(voxelPosition);
voxelPosition.X += 80;
positions[vectorNumber] = voxelPosition;
vectorNumber += 1;
if (j == sizeX) <-- This always executes even though j != sizeX.
{
break;
}
}
voxelPosition.Y += 80;
voxelPosition.X = 0;
}
return positions;
}
}
}
單步執行代碼。驗證'sizeX'是否> 0。如果你的循環從不迭代,那麼在它開始迭代之前滿足退出循環的條件。 – tnw 2013-05-01 15:33:46
在break處設置一個斷點,並確保j和sizeX的值是你期望的(都是499)。 – Cemafor 2013-05-01 15:42:47