This refactoring doesn’t seem to have an official description anywhere, but it’s one I often use. The sign it could be useful is a long method with lots of if statements. Each if statement essentially returns a value of the same type. A loop is really just a sequence of if statements, so often you can make the code cleaner and easier to read by rolling up the if statements into a loop. The trick is to identify an abstraction to loop over.
Ask the group to name some refactorings that they have used, and the corresponding code smells.
Explain what this is. Demonstrate a really simple case.
In the exercise TimerExpiryRefactoringKata show them the duplication in each if statement. Explain the goal - a list of function pointers you loop over. Each function returns the time until the timer goes off. Explain you then just find the smallest value in one place rather than 6 places.
Have them work on the code to achieve the refactoring goal - roll up loop.
Describe this refactoring in your own words. Include