Problem with programming a button

Hello!
Sorry if the grammar isn't correct but I'm not English.
So, I have a proble with programming a button: I have to to run a part of code when I push the button and the it itsn't pushed. When I push the button and it remains pushed it haven't to do nothing, when I don't push the button more, I have to run th part of code.
I've written this part of code and before try it I wanted to know if it was good.

//other code
int val;
int button;

void setup(){
//other code
pinMode(9,INPUT);
}

void loop(){
val=digitalRead(9);
  if(val==HIGH){
    button=1;
  }
  else{
    button=0;
  }
  if(button==1){
    val=digitalRead(9);
  }
  else if(button==0){ 
    //code to run
   }
}

You're doing many things twice. Why assign values to button and then test button? Why re-assign val=digitalRead(9) within microseconds after having just done so? Unless you have a use for button in some other part of your code, this is the same,

void loop()
{
    val=digitalRead(9);
    if(val==HIGH)
    {
        // no need for val=digitalRead(9); as you
        // just read it and it's HIGH
    }
    else
    {
        //code to run
    }
}
boton=1;

means that

if(button==1){

will never be true.
Maybe they are doing different things, but one would never know since you have omitted lines of code. Based on what you have posted, this shouldn't even compile, and if one can't compile it, how would one be able to replicate and fix your issue?

Perehama:

boton=1;

I forgot to translate but they are the same

Check spelling -> boton, button

VittoM:

Perehama:

boton=1;

I forgot to translate but they are the same

One is an accurate translation of the other in language, but to a computer, the name is irrelevant, as long as it is the same. You could call it xyzasdf as long as you call it the same name everywhere. Also, it is case sensitive, meaning upper case capital letters must be the same and lower case minuscule letters must match.

//code
  boolean val;
  int button_condition;

void setup(){
//code
pinMode(9,INPUT);
}

void loop() {
  val=digitalRead(9);
  if(val==HIGH){
    button_condition=1;
  }
  else {
   if(button_condition==1){
    //code
   }
  }
}

Delta_G:

 if(button_condition=1){

Oopsies

Are you assigning a value or comparing a value here?

Sorry,

if(button_condition==1{

VittoM:
Sorry,

if(button_condition==1{

Read *carefully *the syntax for an if() statement. The compiler cares not a whit what you *meant *to say.