how to exit if loop to pr0coeed to the other if statements?

i would like to code something like this

	void Update () 
	{
		if ((player.transform.position.z-other.transform.position.z) > 27 )
		{
			Destroy(other,0.5f);			
		}
		if ((player.transform.position.z-other1.transform.position.z) > 27)
		{
			Destroy(other1,0.5f);
		}
		if ((player.transform.position.z-other2.transform.position.z) > 27)
		{
			Destroy(other2,0.5f);
		}
		if ((player.transform.position.z-other3.transform.position.z) > 27)
		{
			Destroy(other3,0.5f);
		}
		if ((player.transform.position.z-other4.transform.position.z) > 27)
		{
			Destroy(other4,0.5f);
		}
		if ((player.transform.position.z-other5.transform.position.z) > 27)
		{
			Destroy(other5,0.5f);
		}
	}

which the diffences of the distances in z axis will result in destroy of the other game object. the player will always moves front so i need it to update everytime.

the problem i facing now is the loop only execute the 1st 1, is it possible for me to proceed to next if loop?
or should i use others method like switch?
guild and tips is needed by u all =) thanks

What do you mean ‘if loop’? these are just if statements.

And taking a look at your code, there is no reason why any if statement should be skipped.

Unless the object being destroyed is the object running the above script…

You should add a check for “otherX != null” in all the if statements because else you will have errors in the Update cycle after you destroy the objects.

Also I would transfer the check&destroy code in a function since it is the same for each statement:

void CheckOther(GameObject otherObject) {
	if (otherObject == null)
		return;
	if ((player.transform.position.z - otherObject.transform.position.z) > 27) {
		Destroy(otherObject);
	}
}
void Update() {
	CheckOther(other);
	CheckOther(other1);
	CheckOther(other2);
	CheckOther(other3);
	CheckOther(other4);
}