Hi forum! I'm trying to learn from a book that recommends trying to count backwards from 100 to zero using the serial monitor. I tried:
but Serial Monitor only counted down until it reached 55:
...
16:00:15.210 -> index: 57
16:00:15.210 -> index: 56
16:00:15.210 -> index: 55
16:00:15.210 -> index
If "index > -1 " is replaced with any number up to 41 (for example "index > 26" or "index > 41"), it still only counts down to 55
HOWEVER
if I use "index > 42" or any number between 42-53, The serial monitor will count down past 55 until it reaches the number.
For example:
yields:
...
16:02:20.107 -> index: 45
16:02:20.107 -> index: 44
16:02:20.107 -> index: 43
1. Why is it stopping at 55 when using numbers below 42?
2. Why do numbers 42-53 allow me to go lower than 55 while numbers lower than 42 do not?
3. How do I get serial monitor to count down to 0?
Thanks!
P.S. Is it a coincidence that 42 is the answer to the meaning of life, the universe, and everything?
Code:
void setup() {
for (int index = 100; index > -1; index--)
{
Serial.print ("index: ");
Serial.println (index);
}
}
void loop() {
}
but Serial Monitor only counted down until it reached 55:
...
16:00:15.210 -> index: 57
16:00:15.210 -> index: 56
16:00:15.210 -> index: 55
16:00:15.210 -> index
If "index > -1 " is replaced with any number up to 41 (for example "index > 26" or "index > 41"), it still only counts down to 55
HOWEVER
if I use "index > 42" or any number between 42-53, The serial monitor will count down past 55 until it reaches the number.
For example:
Code:
void setup() {
for (int index = 100; index > 42; index--)
{
Serial.print ("index: ");
Serial.println (index);
}
}
void loop() {
}
yields:
...
16:02:20.107 -> index: 45
16:02:20.107 -> index: 44
16:02:20.107 -> index: 43
1. Why is it stopping at 55 when using numbers below 42?
2. Why do numbers 42-53 allow me to go lower than 55 while numbers lower than 42 do not?
3. How do I get serial monitor to count down to 0?
Thanks!
P.S. Is it a coincidence that 42 is the answer to the meaning of life, the universe, and everything?