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?
Solutionvoid 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: