perform if-based condition only once or multiple times?

brice3010:
A if-condition is performed as long as the condition is met. If however the if-condition is met and the execution of the code contained in the if-condition is done once and if this satisfies my program requirements, is it better to include a extra condition so that the if-condition based code is executed only once, or should I keep for simplicity and just let it run as long as the original condition is met?

For example: an if-condition is based on a digital sensor input, and when the condition is met then a LED is lit up. Now as long as the condition is met, a digital write will be done to set the LED digital output high, in fact continually writing a hig to this particular output.

Would it be better programming practice to write code so that this digital write to high is done only once?
Or is it as good to continuously write a high to the LED output as long as the if condition is being met (making for some less complex programming)?

IF your program has nothing else to do, continuously writing HIGH or LOW to a pin changes nothing. For you example, you need to know when to change from writing HIGH to writing LOW.

LEDs don't care. The Arduino pin doesn't care. A relay control doesn't care.

Paul