From the course: Grasshopper and Rhino: Python Scripting

Unlock the full course today

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

While loop

While loop

From the course: Grasshopper and Rhino: Python Scripting

Start my 1-month free trial

While loop

- [Instructor] The while loop is the second of two loops available to us is Python. Unlike the for loop the while loop will loop until a condition is false. Think of a while loop like a set of traffic lights. While the light is green traffic will continue to drive through until a condition tells the traffic to stop. Such as a red light. This is how a while loop works. It will continue to execute a set of instructions until a condition tells it to stop. Let's say for example, we had a variable named Var which equaled zero. For a while loop we need a condition. Say Var is less than five. This is the condition that will tell the loop to stop. While Var is less than five the while loop will run executing whatever is written within the loop. Therefore, the Var variable needs to increment. Meaning, it needs to increase with each loop or the loop will continue to execute with no end causing Grasshopper to crash at the very least. So for example, if the variable started at zero and we…

Contents