How can polymorphism replace an if-else statement or Switch inside of a loop? In particular can it always replace an if-else? Most of the if-thens I use inside of loops are arithmetic comparisons. This question is spawned from this question.
int x; int y; int z; while (x > y) { if (x < z) { x = z; } }
How would this work with polymorphism?
NOTE: I wrote this in Java but am interested in this for any OOL.
Polymorphism usually replaces switch statements when each case corresponds to a different type. So instead of having:
you’d have:
However, for the comparison type of decision you provided, polymorphism really doesn’t help.