changing an variable inside an "if"

Got the answer by AWOL Thank you :slight_smile:

Question::
Hello. i wonder how can i change a variable that is used globally in my program, but change it inside an “if”.

code:
void loop(){
int x = 1;
if (digitalRead(Knapp[1]) == 1) Knapp[1] means button number one. i have 4 buttons on a card.
{int x = 2;}

Serial.println(x);}

this is not the program. but getting a good answer to this will help me soulve the problem myself. thank you a lot guys!

int x = 2;}

You're declaring a new variable x that immediately does out of scope. Lose the "int"

Sp. "goes"

i wonder how can i change a variable that is used globally in my program, but change it inside an "if".

The example does not make sense, nether does the question. Change what to what?