Home Forums C Programming How to avoid if else… Re: Re: How to avoid if else…

#3580
GWILouisaxwzkla
Participant

This is really the only way to do this in C ( if your decision was based on constants I would suggest a “switch” statement ). You could could also use “goto”‘s and lables but this would be bad programming practice and the compiler will generate the same type of code at the assembly level anyway. You could also use “function pointers” in an array and make the variable ‘n’ index this array and then call the proper function , but this might be a waste of memory even thought you avoid testing a value for each “if” statement. I’d probably stick with the “if” chain ……..