17.07.2011, 18:21
Well, its about what you want. Every function call takes some cpu time, so the first variant will be slower than the second one. Therefore it does not use a variable, so it uses less ram. So you have to decide if you want low cpu load or low ram useage, these are the common two options when optimizing code.
"else" is always a good thing to use when you are sure that only one condition will be true, as you dont have to check all the others then, but especially in situations like this i would recommend "switch", this should be more efficient than both "if" variants.
"else" is always a good thing to use when you are sure that only one condition will be true, as you dont have to check all the others then, but especially in situations like this i would recommend "switch", this should be more efficient than both "if" variants.