質問

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.

役に立ちましたか?

解決

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

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top