From the course: Grasshopper and Rhino: C# Scripting

Unlock the full course today

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

Looping with the for loop

Looping with the for loop

From the course: Grasshopper and Rhino: C# Scripting

Start my 1-month free trial

Looping with the for loop

- [Instructor] As in Grasshopper, we often need to perform a single or set of instructions for many items in a collection. Say, for example, we have a list of numbers. We may want to create a list of points or objects based on those numbers. In C sharp, we do this with a programming concept known as looping. Looping allows us to execute an instruction repeatedly until a certain condition is met. One common way of doing this in C sharp is with the for-loop, which comes in this format. We start with the keyword for and then three statements in parenthesis. The first statement is a variable, which is usually an integer. This variable is used in a condition each time the loop executes, and can also be used in a code with each loop. We then have a boolean expression, which is required to determine when the loop will end. Lastly, we have a step which will either increment or decrement each time the loop runs. With…

Contents