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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Variables6m 23s
-
(Locked)
Numbers7m 36s
-
(Locked)
Strings9m 16s
-
(Locked)
Lists and tuples9m 25s
-
(Locked)
Comparing with operators6m 23s
-
(Locked)
Making decisions with conditionals7m 48s
-
(Locked)
Comparing Booleans8m 42s
-
(Locked)
For loop7m 52s
-
(Locked)
While loop8m 43s
-
(Locked)
Nested loops5m 38s
-
(Locked)
Defining custom functions9m 45s
-
-
-
-