Refactoring: Avoiding the use of Each, but using while instead in the print_only_with_conds method