Understanding for-loop

Hey Guys,

I try to understand the following for-loop from the standard code 03.analog => Smoothing

for (int thisReading = 0; thisReading < numReadings; thisReading ++) {
readings [thisReading] = 0:
}

I was wondering if it counts an extra number at thisReading after it finish the code between {} or does it counts before the code {}

So is the first indexnumber 0 or does it starts with the indexnumber 1

I hope you can help me, I'm just a beginner and try to understand the code.
Many thanks!

Starts at 0. It will increment to 1 after the first iteration. A for loop will always execute the code in the {} at least 1 time.

Allright, Thanks for you help groundFungus!

Why don’t you write a small code with that for loop and print the numbers and see? That would be a whole lot faster than asking the forum and you wouldn’t have to take our word for it. Lots of stuff you can just test yourself like that.

Delta_G:
Why don’t you write a small code with that for loop and print the numbers and see? That would be a whole lot faster than asking the forum and you wouldn’t have to take our word for it. Lots of stuff you can just test yourself like that.

Thanks for the tip Delta_G, i will try that next time

groundFungus:
A for loop will always execute the code in the {} at least 1 time.

Uhmm, no... Try

for(byte i = 0; i < 0; i++){
  Serial.println("line!");
}

and see how many lines it prints :wink:

Right.