From the course: Grasshopper and Rhino: Python Scripting

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Nested loops

Nested loops

From the course: Grasshopper and Rhino: Python Scripting

Start my 1-month free trial

Nested loops

- Now that we have a good grip on how loops work, let's take a look at nesting loops. This is basically adding one or more loops inside of another loop, which becomes useful when working with nested lists or data trees. I've simply gone ahead and created a range node to create a range of numbers zero through to nine, so let's go ahead and add a Python component, and remove the y input, and we'll change x to numbers. Which will be a list. And we want to operate on integers. Then go ahead and plug the range of numbers into the numbers input, and double-click to open up the Python component. The first thing we need to do is replace the rhino script syntax import with rhino dot geometry as rg. As we'll be creating points and lines later on. To understand how nested loops work, let's create our own nested loop within Python. Start by creating an empty list, which will append points to in the for loop. I'm gonna call mine points. Next, let's create a for loop, like we did in previous…

Contents