Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Logan Bresnahan
Logan Bresnahan
3,389 Points

Can you write a code block within a code block?

For instance something like this:

10.times do |x|
      #some random code here
         10.times do |y|
              #random code

2 Answers

Victor Learned
Victor Learned
6,976 Points

Yes you can have nested statements. Be careful though since this can decrease a program's performance in more complicated programs depending on what you are doing. (I'm talking about large loops that have large loops that have large loops etc etc)