Loops

  • While Loop Password Example

    Here’s a program that asks for a password and loops repeatedly until you enter the correct password. Some important points about this program:

    Read more

  • Break and Continue

    The break and continue keywords, or similar, are found in most programming languages. Break Example Note that you can use while True to create an “infinite loop”. You can then use break to stop the loop at the desired point. Continue Example

    Read more

  • While Loops

    Most often the kind of loop we need is a for loop. This iterates a specified number of times. However, sometimes we don’t know in advance how many times the loop should iterate. In this case we use a while loop instead. The while loop must be supplied with a condition (an expression that evaluates…

    Read more

  • “for” Loops

    The most common kind of loop in most programming languages is the for loop. This has a slightly different syntax in different programming languages. Python’s implementation of for loops is particularly unusual, and interestingly different. Here’s an example of how it looks in Python. Here, i is simply the name of a loop variable which…

    Read more

Blog at WordPress.com.