From the course: Dynamo for Revit: Python Scripting

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Break and continue

Break and continue

- [Instructor] When working with loops, there are several keywords we can use with loops to help control the flow of them. Two useful ones are the break and continue keywords. Let's start by having a look at the break keyword. In a new Dynamo file, go ahead and place a new Python Script, and then, open it up. Break simply exits a loop at any point. For example, let's create a loop which executes until it reaches 15. We'll do this by utilizing the break keyword. Start by creating a var variable, which equals zero, and an empty list called output. Then, let's create a new while loop with the condition var less than or equal to 20. Inside of the while loop, let's simply append var. Then, let's create a statement within this loop to check if var is 15, and if so, we will utilize this keyword, break, and then, outside of this if statement, increment var by one. So what this while loop will do is continue to execute while var is less than or equal to 20. However, if var equals 15, it will…

Contents