top of page
  • Megan Silvey

Looping


Looping in programming is a quick and easy way to repeat a task multiple times. For example, if you need to individually print out all 100 items in a list, this can take an extremely long amount of time and coding to accomplish with individual print statements. This is where looping comes in handy allowing the computer to do the hard work of printing out each item with just a few instead of a hundred lines of code. There are multiple types of loops such as for loop and while loops.


Loops usually begin with a header defining what it is that they are looping through. For example, they may be looping through a list, a range of values, or a DataFrame column. Once the header is defined, then there is the body of the loop which defines what to do for each iterated item within the loop. Loops are extremely flexible allowing a large variety of tasks to be conducted within them. This includes printing out variables, counting values, conducting if/else statements, and defining new variables. Next time you have a task that needs to be repeated multiple times within code, look into using a loop to ease the burden of typing out a lot of unnecessary code.

15 views0 comments

Recent Posts

See All

MATLAB

bottom of page