How can I have an action happen, except when a variable is a certain value?

I’m developing a game which involves teleporting between different rooms. There are 3 rooms. I’m trying to make it so when you’re in the third room (room == 3), you can’t teleport that direction a fourth time. Same with if you’re in the first room.
Here is my code:

var room = 1;
function Update () 
{
	if(Input.GetButtonDown ("E")){
		transform.position.z += 23.7587996;
		room+=1;
	}
	if(Input.GetButtonDown ("Q")){
		transform.position.z += -23.7587996;
		room+=-1;
		}
	}
}

Is there some sort of if-then statement I can use to achieve this?

I believe you want to use the conditional-AND operator, &&.

var room = 1;
function Update () 
{
    if(Input.GetButtonDown ("E") && room != 3 ){
       transform.position.z += 23.7587996;
       room++;
    }
    if(Input.GetButtonDown ("Q") && room!= 1){
       transform.position.z += -23.7587996;
       room--;
       }
    }
}

The && operator returns true if both statements are true.