user16192: I'm new to Arduino so this may be a really silly doubt but I'm not finding an explanation for it anywhere online. I first uploaded this code (to blink 5 LEDs) on my Arduino Uno :
 void setup(){
 pinMode(12, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(8, OUTPUT);
}

void loop(){
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
delay(1000);
digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
delay(1000);
digitalWrite(10, HIGH);
delay(1000);
digitalWrite(10, LOW);
delay(1000);
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
delay(1000);
}

The 5 LEDs glowed brightly. But when I uploaded the following code (using an if statement to reduce the size of the previous one), the LEDs glowed dimly. 
int LEDpin = 13;
void setup(){
pinMode(LEDpin, OUTPUT);
}

void loop(){
digitalWrite(LEDpin, HIGH);
delay(1000);
digitalWrite(LEDpin,LOW);
delay(1000);
if(LEDpin >= 8){
LEDpin--;
} else {
  LEDpin = 8;
  }
}

Also, when I just typed the if statement without the else part, nothing happened after the LED at pin 8 had glowed on and off. Can someone please tell me why the LEDs glowed dimly in the second one and why nothing glowed after LED 8 when I skipped the else part?

user3493: As Abhishek Jain explained, the pin's need to be initialised for OUTPUT.
However there is another error.
The code in loop() counts down to 8, once, flashing the LEDs, but then only lights an LED on pin 8 because it always goes through the else which maintains LEDpin's value as 8. LEDpin needs to be reset to 12, after it passes 8.
Better code might be
int LEDpin = 12;
void setup(){
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop(){
  digitalWrite(LEDpin, HIGH);
  delay(1000);
  digitalWrite(LEDpin,LOW);
  delay(1000);
  if(LEDpin >= 8){
    LEDpin--;
  } else {
    LEDpin = 12;   // <---- start with the first LED again
  }
}

For what its worth, I wouldn't do the code this way. I would write something using for loops, like:
const int firstLED = 8;
const int lastLED = 12;
int LEDpin;

void setup() {
  for (LEDpin = firstLED; LEDpin <= lastLED; ++LEDpin) {
     pinMode(LEDpin, OUTPUT);
  }
}

void loop() {
  for (LEDpin = firstLED; LEDpin <= lastLED; ++LEDpin) {
    digitalWrite(LEDpin, HIGH);
    delay(1000);
    digitalWrite(LEDpin,LOW);
    delay(1000);
  }
}


user13197: As Abhishek mentioned in his answer is correct, but the better way is to use for loops while dealing with many led's.
Let's say you have led's connected from pin 2 to 8.
int pin = 2;
void setup() 
{
   for (Pin = 2; Pin < 8; Pin++) 
   {
     pinMode(Pin, OUTPUT);
   } 
}
void loop() 
{
   for (int Pin = 2; Pin < 8; Pin++) 
   {
     digitalWrite(Pin, HIGH);
     delay(1000);
     digitalWrite(Pin, LOW);
     delay(1000);
    }
}


16192: <p>I'm new to Arduino so this may be a really silly doubt but I'm not finding an explanation for it anywhere online. I first uploaded this code (to blink 5 LEDs) on my Arduino Uno :</p>

<pre><code> void setup(){
 pinMode(12, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(8, OUTPUT);
}

void loop(){
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
delay(1000);
digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
delay(1000);
digitalWrite(10, HIGH);
delay(1000);
digitalWrite(10, LOW);
delay(1000);
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
delay(1000);
}
</code></pre>

<p>The 5 LEDs glowed brightly. But when I uploaded the following code (using an if statement to reduce the size of the previous one), the LEDs glowed dimly. </p>

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

void loop(){
digitalWrite(LEDpin, HIGH);
delay(1000);
digitalWrite(LEDpin,LOW);
delay(1000);
if(LEDpin &gt;= 8){
LEDpin--;
} else {
  LEDpin = 8;
  }
}
</code></pre>

<p>Also, when I just typed the <code>if</code> statement without the <code>else</code> part, nothing happened after the LED at pin 8 had glowed on and off. Can someone please tell me why the LEDs glowed dimly in the second one and why nothing glowed after LED 8 when I skipped the <code>else</code> part?</p>
 3493: <p>As Abhishek Jain explained, the pin's need to be initialised for OUTPUT.</p>

<p>However there is another error.</p>

<p>The code in <code>loop()</code> counts down to 8, once, flashing the LEDs, <strong>but</strong> then only lights an LED on pin 8 because it always goes through the <code>else</code> which maintains LEDpin's value as 8. LEDpin needs to be reset to 12, after it passes 8.</p>

<p>Better code might be</p>

<pre><code>int LEDpin = 12;
void setup(){
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop(){
  digitalWrite(LEDpin, HIGH);
  delay(1000);
  digitalWrite(LEDpin,LOW);
  delay(1000);
  if(LEDpin &gt;= 8){
    LEDpin--;
  } else {
    LEDpin = 12;   // &lt;---- start with the first LED again
  }
}
</code></pre>

<p>For what its worth, I wouldn't do the code this way. I would write something using for loops, like:</p>

<pre><code>const int firstLED = 8;
const int lastLED = 12;
int LEDpin;

void setup() {
  for (LEDpin = firstLED; LEDpin &lt;= lastLED; ++LEDpin) {
     pinMode(LEDpin, OUTPUT);
  }
}

void loop() {
  for (LEDpin = firstLED; LEDpin &lt;= lastLED; ++LEDpin) {
    digitalWrite(LEDpin, HIGH);
    delay(1000);
    digitalWrite(LEDpin,LOW);
    delay(1000);
  }
}
</code></pre>
 13197: <p>As Abhishek mentioned in his answer is correct, but the better way is to use for loops while dealing with many led's.</p>

<p>Let's say you have led's connected from pin 2 to 8.</p>

<pre><code>int pin = 2;
void setup() 
{
   for (Pin = 2; Pin &lt; 8; Pin++) 
   {
     pinMode(Pin, OUTPUT);
   } 
}
void loop() 
{
   for (int Pin = 2; Pin &lt; 8; Pin++) 
   {
     digitalWrite(Pin, HIGH);
     delay(1000);
     digitalWrite(Pin, LOW);
     delay(1000);
    }
}
</code></pre>
