From the course: Learning ArcGIS Python Scripting (2018)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Use loops to work with lists - ArcGIS Tutorial
From the course: Learning ArcGIS Python Scripting (2018)
Use loops to work with lists
- [Instructor] When you have a list of data that you wanna run some code on, you use a looping construct. A loop lets you execute a set of code over and over again. For example, you can do something to all the feature classes in a geodatabase, all of the layers in a map, or all of the text files in a folder. Loop blocks start with a specific line of code, the word, for, or while, or for each, and the first line has to end with a colon. The next line, and all of the lines that are part of the loop block must be indented, to exactly the same number of characters. It's the indention that determines what is a part of the loop. You end the loop by moving the next line of code back to the margin with no indention. By the way, you can have loops inside of loops, and it's very common in scripting. The indention for each loop can be any number of spaces, but all the lines in a single loop have to be indented by exactly the same number of spaces. There are several kinds of loops that are built…
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.