program driving me crazy

i have problem with while loop that when i add it to the script it keeps looping and never let me out of it and make other function in the void loop never work.

this is the while loop:

while (state == 1){
       digitalWrite(A2, HIGH);
        delay(2000);
        digitalWrite(A2, LOW);
        delay(2000);
    if (state == 0)
        {
          break;  
            
        }
        
    }

(deleted)

edited OP

(deleted)

added full code already

(deleted)

Your program enters the loop so the only thing it does is what's inside the loop. In the while loop u don't change the value of the state so it's always the same. How can u expect it to leave the while? And you have a if testing if state is 0 when that part of the code will only run as long as the state is 1. :) :)

i added the if so as when i change from state flag from 1 to 0 it break the while loop and turn off the led x.x . seems i miss something but i cant get it :S

seems i miss something

Code tags?

i fixed it, really sorry but i am new in this forum so bare with me also i tried to find a solution through forum before i post but the while loop driving me crazy. all i need is to make the led blink when the state is 1 and turn off when state is 0 but its confusing me

so bare with me

Never on a first date

while (state == 1){
       digitalWrite(A2, HIGH);
        delay(2000);
        digitalWrite(A2, LOW);
        delay(2000);
    if (state == 0)

How likely is it that state is going to be equal to zero there?

When you enter the loop the code that run is what's inside. Since you aren't testing the state the state won't change man so it won't leave the loop

got you, i got the idea and i will fix it by myself :) appreciate everyones help ^^