user3700: My question is simple. Does Arduino set the digitalwrite() the moment it is called or at the end of the while loop. E.G.
int ledPin = 13;               
void setup()
{
  pinMode(ledPin, OUTPUT);      
}

void loop()
{for(int i=0; i<10; i++){
if(i%2==0){
  digitalWrite(ledPin, HIGH);   
  delay(1000);}else{                  
  digitalWrite(ledPin, LOW);    
  delay(1000);      }           
}


user3493: A key point of the Arduino 'language' is every statement is completed before the next one can begin. 
A simple statement has a ';' at the end of it.
Or followed by ')' instead of ';' in for (...; ...; statement) loop.
So digitalWrite() will set the pin, HIGH or LOW, before it completes and allows the next statement, delay(...) to begin.
Side note:
Actually digitalWrite() takes a small amount of time to do its work, so it is not exactly 'the moment' it is called. digitalWrite() is pretty quick, a few millionths of a second, which is usually near enough to be practically 'the moment' for most applications. 

3700: <p>My question is simple. Does Arduino set the digitalwrite() the moment it is called or at the end of the while loop. E.G.</p>

<pre><code>int ledPin = 13;               
void setup()
{
  pinMode(ledPin, OUTPUT);      
}

void loop()
{for(int i=0; i&lt;10; i++){
if(i%2==0){
  digitalWrite(ledPin, HIGH);   
  delay(1000);}else{                  
  digitalWrite(ledPin, LOW);    
  delay(1000);      }           
}
</code></pre>
 3493: <p>A key point of the Arduino 'language' is <em>every</em> statement is completed before the next one can begin. </p>

<p>A simple statement has a '<code>;</code>' at the end of it.<br>
Or followed by '<code>)</code>' instead of '<code>;</code>' in <code>for (...; ...; statement)</code> loop.</p>

<p>So <code>digitalWrite()</code> will set the pin, HIGH or LOW, <em>before</em> it completes and allows the next statement, <code>delay(...)</code> to begin.</p>

<p>Side note:<br>
Actually <code>digitalWrite()</code> takes a small amount of time to do its work, so it is not <em>exactly</em> 'the moment' it is called. <code>digitalWrite()</code> <em>is</em> pretty quick, a few millionths of a second, which is usually near enough to be practically 'the moment' for most applications. </p>
