Programming Examples

Write a program to implement a while loop that counts from 0 to 10 and displays each count on the Serial Monitor.


Write a program to implement a while loop that counts from 0 to 10 and displays each count on the Serial Monitor. What happens if you

accidentally create an infinite loop in this case?

Solution

void setup() {
  Serial.begin(9600);   // Start serial communication

  int count = 0;        // Initialize counter

  while (count <= 10) { // While count is less than or equal to 10
    Serial.println(count);
    count++;            // Increment counter
  }
}

void loop() {
  // Empty loop (not needed for this task)
}
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad