From the course: Dynamo for Revit: Python Scripting

Unlock the full course today

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

Looping with the while loop

Looping with the while loop

From the course: Dynamo for Revit: Python Scripting

Start my 1-month free trial

Looping with the while loop

- [Narrator] The While Loop is the second of two loops available in Python. Unlike the ForLoop, 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 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 have a variable named Var, which equals zero. For a While Loop, we need a condition, say Var less than five. This is the condition that will tell the loop to stop. While Var 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 Dynamo to crash. So for example, if we increment the variable by one inch loop, the loop will run five times…

Contents