Advertisement
themaleem

quickmail

Sep 12th, 2024
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.44 KB | Source Code | 0 0
  1. def print_numbers
  2.   (1..100).each do |num|
  3.     if num % 15 == 0
  4.       puts 'APingBPong'
  5.     elsif num % 3 == 0
  6.       puts 'APing'
  7.     elsif num % 5 == 0
  8.       puts 'BPong'
  9.     else
  10.       puts num
  11.     end
  12.   end
  13. end
  14.  
  15. print_numbers
  16.  
  17. # - Order of Conditions: Checking for multiples of both 3 and 5 (num % 15 == 0) is prioritized because if this check were
  18. # placed later, the individual checks for 3 and 5 would catch those numbers first.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement