Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. def sum_with_while(min, max)
  2. # CONSTRAINT: you should use a while..end structure
  3. array = (min..max).to_a
  4. sum = 0
  5. count = 0
  6. if min > max
  7. return -1
  8. else
  9. while count < array.length
  10. sum += array[count]
  11. count += 1
  12. end
  13. end
  14.  
  15. return sum
  16. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement