About 27,500,000 results
Open links in new tab
  1. Checking loop in Python - Stack Overflow

    Jun 5, 2018 · How would You write a loop which checks if the previous number is lower, and the next after the checked one (Condition looks like this [5,6,5]). So the loop will get to number 9 and print it or save it, whatever. Using next with a generator expression: If you need all such numbers, use a list comprehension instead:

  2. 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 over a range from 0 to n-1 (where n = 4). We can use for loop to iterate lists, tuples, strings and dictionaries in Python.

  3. Python: While Loop Check Throughout Loop if True

    Oct 23, 2013 · If you want a checked in more places, you're going to have to insert code to explicitly check it in those places. Use: print('hi') a = False. if not a: break. print('bye') In a function or loop, when something is return ed, the function or loop terminates. You could also return True, or break which is a specific way to 'break' out of a loop.

  4. python - Get a Try statement to loop around until correct value ...

    Feb 11, 2010 · I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below: try: print 'Please select one of the following?\nCompletion = 0\nRelease ID = 1\nVersion ID = 2\nBuild ID = 3\n'

  5. Python While Loops - W3Schools

    Python has two primitive loop commands: With the while loop we can execute a set of statements as long as a condition is true. Note: remember to increment i, or else the loop will continue forever. The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1.

  6. Python Conditional Statements and Loops

    Read all the tutorials related to the topic of Python Sets. Loops in Python. Loops allow you to execute a block of code multiple times. Python provides two main types of loops: for loops and while loops. For Loops. The for loop in Python is designed to iterate over a sequence (like a list, tuple, dictionary, set, or string):

  7. Python Control Flow and Loops (Learning Path) – Real Python

    Learn how to emulate do-while loops in Python. The most common technique to do this is to create an infinite while loop with a conditional statement that controls the loop and jumps out of it using a break statement. Learn how to check if a given value is present or absent in a collection of values using Python's in and not in operators.

  8. Keep Calling a Function Until a Condition is Met - Python

    Dec 16, 2024 · In Python, we can use a loop to repeatedly call a function until a condition is met. This is useful for tasks that require continuous checking, such as waiting for a process to complete or retrying an operation until it succeeds. It ensures the function runs as long as the condition remains false. Example: Explanation:

  9. Python while Loops: Repeating Tasks Conditionally

    Python lacks a built-in do-while loop, but you can emulate it using a while True loop with a break statement for conditional termination. With this knowledge, you’re prepared to write effective while loops in your Python programs, handling a wide range of iteration needs.

  10. Mastering Loops in Python: A Comprehensive Guide

    6 days ago · Loops are a fundamental concept in programming that allow you to execute a block of code repeatedly. In Python, loops are incredibly versatile and are used in a wide range of applications, from simple iterative tasks to complex data processing. Understanding how to use loops effectively can greatly enhance your programming skills and enable you to write more efficient and concise code.

Refresh