Asking about the time from n=0 to n=10.

I have a question. May I ask about the time of it ?

For the while loop, I count it from n=0 to n=10. Then break the loop, do anyone know about what's the actual time from n=0 to n=10?

int ledPin = 10; //Set Pin 10 as led Pin int n=0;

void setup() { pinMode(ledPin, OUTPUT);//Set ledPin as output Serial.begin(9600); //setting serial monitor at a default baund rate of 9600 } void loop() { Serial.println(1); analogWrite(ledPin, 255); //led on while(n==0) {n++; if( n ==10) { n=0; break; } } Serial.println(0); analogWrite(ledPin, 0); //off led while(n==0) {n++; if( n ==10) { n=0; break; } } }

while(n==0)
   {
     n++;
     if( n ==10) 
      { 
         n=0;
         break;
      }                  //delay 0.02s = 50HZ
   }

First time through the while n is increnmented to 1, n is not equal to 10 so the if block is skipped. Then it loops back to the while and it exits from the while because n equals 1. So the execution time is very short.

If you want to measure execution time, right before you enter the loop, record the start time using micros(). Run through the loop and record the end time when the loop finishes. The difference is the execution time.

groundfungus: while(n==0)   {     n++;     if( n ==10)       {         n=0;         break;       }                  //delay 0.02s = 50HZ   }

First time through the while n is increnmented to 1, n is not equal to 10 so the if block is skipped. Then it loops back to the while and it exits from the while because n equals 1. So the execution time is very short.

Yup I know Sir...... Can I ask about the actual time of the execution time..?