From: pedro oliva Date: 2013-06-06T09:19:47+09:00 Subject: Need help understanding recursion. Ive been reading Chris Pine's book 'Learn to Program' and its been going great up until I got to chapter 10 on recursion and thus has completely taken all my excitement from going forward. I understand that recursion is a method that will continue to call itself till there is an attribute to cause it to exit the loop. The example in the book though has me all sorts of confused. Can someone walk me through the example and bring back the excitement to continue to learn Ruby! M = 'land' o = 'water' world = [ [o,o,o,o,o,M,o,o,o,o,o], [o,o,o,o,M,M,o,o,o,o,o], [o,o,o,o,o,M,o,o,M,M,o], [o,o,o,M,o,M,o,o,o,M,o], [o,o,o,o,o,M,M,o,o,o,o], [o,o,o,o,M,M,M,M,o,o,o], [M,M,M,M,M,M,M,M,M,M,M], [o,o,o,M,M,o,M,M,M,o,o], [o,o,o,o,o,o,M,M,o,o,o], [o,M,o,o,o,M,M,o,o,o,o], [o,o,o,o,o,M,o,o,o,o,o]] def continent_size world, x ,y if x < 0 or x > 10 or y < 0 or y > 10 return 0 end if world[y][x] != 'land' return 0 end size = 1 world [y][x] = 'counted land' size = size + continent_size(world, x-1, y-1) size = size + continent_size(world, x , y-1) size = size + continent_size(world, x+1, y-1) size = size + continent_size(world, x-1, y ) size = size + continent_size(world, x+1, y ) size = size + continent_size(world, x-1, y+1) size = size + continent_size(world, x , y+1) size = size + continent_size(world, x+1, y+1) size end puts continent_size(world, 5, 5) -- Posted via http://www.ruby-forum.com/.