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)
}
▶ RUN

Output/ Explanation:

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad