Need help with Audino programing

// EXAMPLE 02: Turn on LED while the button is pressed
//
// Copy and paste this example into an empty Arduino sketch

#define LED 10 // the pin for the LED
#define BUTTON 7 // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}

void loop(){
val = digitalRead(BUTTON); // read input value and store it

// check whether the input is HIGH (button pressed)
if (val == HIGH) {
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW); // turn LED OFF
}
delay (500); // waits for a second
}

This is what i got so far. This basically allows me to turn on the LED when I press the button only one time. I want the LED to turn on when I press the button twice. For example every even presses it turns on and goes out after I take my finger off the button. The delay has to stay the same.

I want the LED to turn on when I press the button twice.

You need to count how many times the switch has been pressed. To do that, you need to know when the switch becomes pressed, not is pressed. Look at the state change detection example.

so i should start a new sketch? isn't there anyway to modify the current one, so that 2 press on the button can turn the light on?

isn't there anyway to modify the current one,

Of course there is. That's why text editors were invented.

The question was how to modify the sketch, and the answer is in the state change detection example and counting presses, every time the switch BECOMES pressed (not IS pressed).

I don’t understand what you mean by switch becomes pressed, but i do understand that the problem is under the void loop and with (val == HIGH), which basically means when button is pressed it turns on, but isn’t it the same thing as when button become pressed as that will also turn the light on?

#define LED 10 // the pin for the LED
#define BUTTON 7 // the input pin where the
// pushbutton is connected
int val = 0;
int buttonPushCounter = 0;
int lastValState = 0;

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
}

void loop(){
val = digitalRead(BUTTON);

// check whether the input is HIGH (button pressed)
if (val != lastValState) {
if (val == HIGH) {
buttonPushCounter++;
digitalWrite(LED, HIGH); // turn LED ON
} else {
digitalWrite(LED, LOW); // turn LED OFF
}
}
lastValState = val;

if (buttonPushCounter % 2 == 0) {

digitalWrite(LED, HIGH);

} else {

digitalWrite(LED, LOW);

}
delay (500); // waits for a second
}

after modifying the current sketch with the state change this is what I got, but i think i need to modify it even more and add debouncing to get it to work properly, but this will most likely turn on the light after 2 presses right?

but this will most likely turn on the light after 2 presses right?

Haven't you tried it?