PDA

View Full Version : is it better to run a statment all the time or put it in a if statement


hogtied
03-08-2003, 06:24 AM
Hey,

I was wondering would it be better, whether for performance or whatever to run a statement all the time or encase it in an if statement.

for example:

document.form1.options[thisDate].selectedIndex = true;

lets say that the above statement is within a function, and that function is called upon every time a user changes either the month or date of both arrival and/or departure dates. The only instatance that this statement would not have to be read by the computer is if the user selected the date.

it will also work the same if i wrote it this way:

if (object != date) {
document.form1. etc.. etc..
}

Would I benifit anything from doing this. Such as less calculations, faster response, etc. etc,, anything...

Just curious
Thanks
Hogtied

Graeme Hackston
03-08-2003, 01:34 PM
If the condition is almost always true and not required I'd say don't use the if. The condition alone could be a greater work load than the statement.