Pregunta

Please help me interpret this for-loop:

for (byte color_bit = 23 ; color_bit != 255 ; color_bit--) {
    ...do something
}

I think I understand (from Googling & StackOverflow) that 'color_bit' here is an UNSIGNED variable. So this means that the loop will count down from 23 to 0. But then what happens next? Does it attempt to start at 255 and continue to count down? But because the test is "!= 255" it will stop?

In my mind this seems to be the logic, but the tool I'm using (Arduino IDE) doesn't have a debugger, so I can't step through the code to see the values.

¿Fue útil?

Solución

Your loop will see bit_color = 23..0 (24 iterations) provided 'byte' is 8 bit unsigned. Your loop stops when color_bit=255. HTH.

Otros consejos

You could add a serial print line as shown below:

 for (byte color_bit = 23 ; color_bit != 255 ; color_bit--) {
      Serial.print(bit_color, DEC);
 }

To test/debug the counting sequence.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top