# [Solved] Checking if a number if greater than or less than in a for statement?

Discussion in 'Spigot Plugin Development' started by DeadlyBlaze, Jul 13, 2015.

Not open for further replies.

Hi there, how would I check if a number is greater than or less than? Done this so far
Code (Text):
for (int x = max.getBlockX(); x <= min.getBlockX(); x++){
//Something in here
}

2. ### BetaNyan

if (number > other || number < other)

Edit: you said for not if

3. ### BetaNyan

Code (Text):
for (int i = 0; i < number || i > number; i*+)

Thanks, found out why as before I was using >= and <= xD

Okay, done that but it's only removing the blocks at two corrners and not the whole area.

Code:
Code (Text):
for (int x = max.getBlockX(); x < min.getBlockX() || x > min.getBlockX(); x++){
for (int y = min.getBlockY(); y < max.getBlockY() || y > max.getBlockY(); y++){
for (int z = min.getBlockZ(); z < max.getBlockZ() || z > max.getBlockZ(); z++){
max.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
}
}
}

6. ### BillyGalbreath

Code (Text):

int minX = Math.min(max.getBlockX(), min.getBlockX());
int minY = Math.min(max.getBlockY(), min.getBlockY());
int minZ = Math.min(max.getBlockZ(), min.getBlockZ());
int maxX = Math.max(max.getBlockX(), min.getBlockX());
int maxY = Math.max(max.getBlockY(), min.getBlockY());
int maxZ = Math.max(max.getBlockZ(), min.getBlockZ());

for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
max.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
}
}
}

This does not answer this question, but I can see you are wanting to do something completely different. You mentioned this in another thread already, and like I said there, you have to make sure your values are actual min and max first before anything else. Just because you named the location variables max and min doesnt make them that.

• Like x 1