DS18B20 temperature sensor question

Would anyone kindly explain how sensors.getTempCByIndex() works?

I have 5 DS18B20 temperature sensors. I get good readings when I do the following:

Serial.print(sensors.getTempCByIndex(0));
Serial.print(" ");
Serial.print(sensors.getTempCByIndex(1));
Serial.print(" ");

(and repeat this 3 more times)

But I got smarter and put the 5 repetitions in a for loop:

for (int i=0, i=4, i++) {
Serial.print(sensors.getTempCByIndex(i);
Serial.print(" ");
}

I got a strange number. Thank you.

Your for statement has a flawed test condition.

The syntax of your for statement is wrong.

  for (int i=0, i=4, i++) {

Use ';' not ','.

  for (int i = 0; i <= 4; i++) {

THANK YOU so much. I would have not noticed the error by myself.

paker:
THANK YOU so much. I would have not noticed the error by myself.

?

not even when the compiler clobbered you over the head with the errors?

paker:
THANK YOU so much. I would have not noticed the error by myself.

The code you wrote should have produced quite a few compiler errors pointing to the code causing the problem.

So when you said you got 'a strange number' did you mean you had lots of compiler errors ?

srnet:
The code you wrote should have produced quite a few compiler errors pointing to the code causing the problem.

So when you said you got 'a strange number' did you mean you had lots of compiler errors ?

No, I did not have a compiler error. Compiled, uploaded, and executed. Just one number was repeatedly printed over and over.

Which version of the IDE were you using?
I'm using 1.8.4 and the compiler barfs all over that statement:

sketch_dec10a: In function 'void setup()':
sketch_dec10a:50: error: redeclaration of 'int i'
   for (int i=0, i=4, i++) {

                 ^

C:\Users\Peter\AppData\Local\Temp\arduino_modified_sketch_197591\sketch_dec10a.ino:50:12: note: 'int i' previously declared here

   for (int i=0, i=4, i++) {

            ^

sketch_dec10a:50: error: expected ';' before '++' token
   for (int i=0, i=4, i++) {

                       ^

sketch_dec10a:50: error: expected primary-expression before ')' token
   for (int i=0, i=4, i++) {

                         ^

sketch_dec10a:50: error: expected ';' before ')' token
redeclaration of 'int i'

Pete