Stats

1162 Contributors: 56
2017-07-22
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

Loops

Download python eBook

Introduction

As one of the most basic functions in programming, loops are an important piece to nearly every programming language. Loops enable developers to set certain portions of their code to repeat through a number of loops which are referred to as iterations. This topic covers using multiple types of loops and applications of loops in Python.

Syntax

  • while <boolean expression>:
  • for <variable> in <iterable>:
  • for <variable> in range(<number>):
  • for <variable> in range(<start_number>, <end_number>):
  • for <variable> in range(<start_number>, <end_number>, <step_size>):
  • for i, <variable> in enumerate(<iterable>): # with index i
  • for <variable1>, <variable2> in zip(<iterable1>, <iterable2>):

Parameters

ParameterDetails
boolean expressionexpression that can be evaluated in a boolean context, e.g. x < 10
variablevariable name for the current element from the iterable
iterableanything that implements iterations

Related Examples