ข้ามไปยังเนื้อหา

Lesson 4: for loops

English

Do it several times

  • A for loop repeats lines a fixed number of times.
  • for (int i = 0; i < 3; i++) counts i = 0, 1, 2. That is 3 times.
void setup() {
  pinMode(13, OUTPUT);
  for (int i = 0; i < 3; i++) {     // 3 quick blinks
    digitalWrite(13, HIGH);
    delay(200);
    digitalWrite(13, LOW);
    delay(200);
  }
}

void loop() {
}
  • The blinks are in setup(), so they happen once. loop() is empty, so then the board does nothing.

เข้าสู่ระบบหรือสร้างบัญชี

IGCSE, A-Level & AP