Ruby Basic Exercises: Print even numbers from 1 to 10
Ruby Basic: Exercise-27 with Solution
Write a Ruby program to print even numbers from 1 to 10.
Ruby Code:
puts "Even numbers between 2 to 10: "
2.step 10, 2 do |x|
puts "#{x}"
end
Output:
Even numbers between 2 to 10: 2 4 6 8 10
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to print 34 upto 41.
Next: Write a Ruby program to print odd numbers from 10 to 1.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework