I need to execute a block of code several number of times.

I need to execute a block of code several number of times.
How to do that without goto?

In general:
Button==1 execute the loop code.
Button==0 stop and wait for Button to be again Button==1.

So basically, I'm trying to switch between 2 loops with button.

Thank you.

Show us your attempt so far.

Nice cat.
.

use while loops with a condition within each loop to check if button state changes from what started the block. If button changes, break;

void loop(void)
{

 int  value = client.getValue("57d164ef762542127772a44");
 delay(1000);
   
 Serial.println("Got this before while:");
 Serial.println( value);

 
 while( value > 0 ){      // Button on
    int   value = client.getValue("57d164ef762542127772a44");
    delay(1000); 
   
    Serial.println("Got this inside while:");
    Serial.println( value);
 }
}

But even after value changed back to 0 its seems to stuck inside while loop:

Got this inside while:
0

What I'm doing wrong?

You're creating a new variable named value inside the while loop. It's not the same variable you're checking as the condition. The one you're using for the condition never gets updated. It's not the same one you see printed. The one you're printing is the new one.

Lise the "int" in front of value in the while loop. Putting the type creates a new variable. Two variables with the same name is almost never a good idea.

flash_os:
I need to execute a block of code several number of times.
How to do that without goto?

Put the code that needs to be repeated into a function. Then you can call the function whenever needed.

Have a look at Planning and Implementing a Program to see an example of the use of functions.

...R

Thanks guys.
It's worked!