
Patrick B. answered 07/29/19
Math and computer tutor/teacher
I disagree with the belief that if statements are slow and inefficient.
How else can one program anything involving selection without if statements?
If you are programming in a C based language (C/C++/java etc)
there is an alternative selection statement
// finds the absolute value of X
absVal = ( X >= 0) ? X : -X;
which the compiler expands to:
if (X>=0)
{
absVal = X;
}
else
{
ansVal = -X;
}
The only other way would be to tweak the sign bit, assuming
the programming language you are using allows that