Skip to Content
Learn
Loops & Iterators
The .times Iterator

The .times method is like a super compact for loop: it can perform a task on each item in an object a specified number of times.

For example, if we wanted to print out "Chunky bacon!" ten times, we might type

10.times { print "Chunky bacon!" }

We don’t know why we would type that, but we could!

Instructions

1.

Use the .times operator to print out a string of your choice any number of times you like. Use the code in the text above as a guide if you need help.

Folder Icon

Take this course for free

Already have an account?