nest loop inside if/else

+2 Eric Hines · January 9, 2016
Not sure if I'm on the right track or not, so I'm just looking for some points to ponder.

I'm working with arduino uno and to practice the if/else and loop functions this is what I'm considering

if(detect user input)
(blink LED)
else (detect user input)
(turn off LED)

Like I said, I'm not sure if I'm on the right track or just barking up the wrong tree. Someone suggested setting a variable to 0 or 1, when the user does their input the arduino reads the variable and executes the loop to blink indefinitely. when the same input is given again, set the variable to the opposite value.

Post a Reply


Oldest  Newest  Rating
0 Laura Lee · January 10, 2016
That's not necessary. Have a variable to hold the state of the LED. For each input, simply toggle the state.
if(input) state = !state;
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator