About 4,090,000 results
Open links in new tab
  1. python combine 'while loop' with 'for loop' to iterate through

    Jul 25, 2014 · I am trying to combine a while loop with a for loop to iterate through some list but I am getting infinite loops. My code: l=[0,2,3,4] lo=0 for i in range(len(l)): while (True): lo+=1 if …

  2. Python For & While Loops with 15+ Useful Examples

    You can use loops to for example iterate over a list of values, accumulate sums, repeat actions, and so on. In Python, you can use for and while loops to achieve the looping behavior.

  3. For or While loop to print Numbers from 1 to 10 in Python

    Apr 9, 2024 · Use the range() class to loop from 1 to 10 in a for loop, e.g. for num in range(1, 11):. The range class takes start (inclusive) and stop (exclusive) arguments and enables us to loop …

  4. Loops in Python - For, While and Nested Loops - GeeksforGeeks

    Mar 8, 2025 · Let us learn how to use for loops in Python for sequential traversals with examples. Explanation: This code prints the numbers from 0 to 3 (inclusive) using a for loop that iterates …

  5. Using For and While Loops in Python 3 | Linode Docs

    Feb 4, 2022 · A for loop can be paired with the .items method to iterate through all key-value pairs in a Python dictionary. Upon each iteration through the view object, the next key-value tuple is …

  6. Python For loop and if else Exercises [22 Exercise Programs]

    Apr 19, 2025 · This Python loop exercise contains 22 different coding questions, programs, and challenges to solve using if-else conditions, for loops, the range() function, and while loops. …

  7. Python For Loops - W3Schools

    A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). This is less like the for keyword in other programming languages, and works more like …

  8. Loops - Learn Python - Free Interactive Python Tutorial

    There are two types of loops in Python, for and while. For loops iterate over a given sequence. Here is an example: For loops can iterate over a sequence of numbers using the "range" and …

  9. Python For Loop and While LoopPython Land Tutorial

    Jun 5, 2022 · Another way to control the flow is by using a Python for-loop or a Python while-loop. Loops, in essence, allow you to repeat a piece of code. There are two ways to create a loop in …

  10. SOLVED: How to loop n times in Python [10 Easy Examples]

    Jan 9, 2024 · When you want to iterate over the sequence one way is to iterate using the for loop given below that gives the position of the desired element. The example below iterates over …

Refresh