Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def print_numbers
- (1..100).each do |num|
- if num % 15 == 0
- puts 'APingBPong'
- elsif num % 3 == 0
- puts 'APing'
- elsif num % 5 == 0
- puts 'BPong'
- else
- puts num
- end
- end
- end
- print_numbers
- # - Order of Conditions: Checking for multiples of both 3 and 5 (num % 15 == 0) is prioritized because if this check were
- # placed later, the individual checks for 3 and 5 would catch those numbers first.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement