Can I do like this ?

I have a led names LED. I set it to high using

digitalWrite(LED, HIGH);

Now, can I do like this ? LED is an output pin. Can I use it in if() test ?

if(LED) LED = 0;

or

if(LED)digitalWrite(LED, LOW);

Can I use it in if() test ?

You can but as LED will be a pin number it is not going to change so there is little point.

jayanthd:
I have a led names LED. I set it to high using

digitalWrite(LED, HIGH);

Now, can I do like this ? LED is an output pin. Can I use it in if() test ?

if(LED) LED = 0;

or
if(LED)digitalWrite(LED, LOW);

Use a variable to keep track of the state of the LED:

//before setup()
boolean ledState =FALSE;

//in the body of your code
digitalWrite(LED, HIGH);
ledState = !ledState;  //flip state
...
if(ledState ==TRUE){
digitalWrite(LED, LOW);
ledState = !ledState;  //flip state
}

Thank you.

This also worked in hardware. I tested in UNO R3.

int LED = 12;

void setup() {
    pinMode(LED, OUTPUT);
}

void loop() {
  
    if(digitalRead(LED) == 0) {
        digitalWrite(LED, HIGH);
        delay(5000);
    }
    
    if(digitalRead(LED)) {
        digitalWrite(LED, LOW);
        delay(1000);      
    }
  
}

Or:-

digitalWrite(LED, !digitalRead(LED));

Will toggle the LED state.

Thank you Grumpy_Mike

Your code is simple. I have one question. How does the digitalRead(LED) work as LED is an output pin. How is it reading the state of a Output PORT (PIN) ?

This is one of the confusing things about Atmel jargon.

Setting a port as OUTPUT doesn't mean it is only capable of output. It actually means that it has a low impedance so it can supply current (when it is HIGH) or take in current when it is LOW. But not more than 20mA in either direction. And note that an external power supply cannot make a LOW pin go HIGH. If it tries (by passing too much current) it will damage the Arduino.

Setting a port as input sets it in a high impedance mode where it can only supply or take in a tiny current (micro amps?). In this case an external device can make the pin go HIGH or LOW.

In either case the process of reading the value of the PIN is quite separate from its setting.

...R

What you are doing is reading the state of the output latch, which contains the state of the output pin.
See the data sheet for the processor for the equivalent circuit.
I thought you would ask what the ! was doing.

Thank you. That cleared the doubts. Actually I am a PIC guy. I am new to AVR and Arduino.

jayanthd:
Actually I am a PIC guy.

Don't worry - you can still be saved.