About 13,200,000 results
Open links in new tab
  1. python - How to do while loops with multiple conditions - Stack Overflow

    use an infinity loop like what you have originally done. Its cleanest and you can incorporate many conditions as you wish while 1: if condition1 and condition2: break ... ... if condition3: break ... ...

  2. While loop with if/else statement in Python - Stack Overflow

    Apr 25, 2016 · I'm assuming you want to say Less than 2 or Greater than 4 while incrementing from 1 to 4: counter = 1 while (counter < 5): if counter < 2: print('Less than 2') elif counter > 4: print('Greater than 4') else: print('Something else') # You can use 'pass' if you don't want to print anything here counter += 1

  3. 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 …

  4. Python Conditional Statements and Loops

    Learn how to use conditional statements in Python with practical examples. Master if, elif, and else statements to control your program's flow and make decisions.

  5. Python while Loops: Repeating Tasks Conditionally

    while is a Python keyword used to initiate a loop that repeats a block of code as long as a condition is true. A while loop works by evaluating a condition at the start of each iteration. If the condition is true, then the loop executes. Otherwise, it terminates.

  6. Python - Using a while loop with an if/elif statement

    Nov 14, 2015 · You want choice to be either "temp" or "distance", so your while condition should be that it can't (not be "temp" AND not be "distance"). Just substitute the or for and on the while condition. print "Welcome to the converter. What would you like \ print "Sorry, that's not an option" choice = raw_input(prompt) print "temp" print "distance"

  7. Writing a Python While Loop with Multiple Conditions

    Mar 11, 2021 · In this article, you learned how to write a Python while loop with multiple conditions. You reviewed indefinite iteration and how while statements evaluate conditional expressions.

  8. Conditional Statements in Python - GeeksforGeeks

    Apr 4, 2025 · This is a compact way to write an if statement. It executes the print statement if the condition is true. If else Conditional Statements in Python Else allows us to specify a block of code that will execute if the condition (s) associated with an if or elif statement evaluates to False.

  9. Python While Loop with Multiple Conditions - datagy

    Sep 25, 2021 · In this tutorial, you’ll learn how to write a Python while loop with multiple conditions, including and and or conditions. You’ll also learn how to use the NOT operator as …

  10. Conditional Loops — Introduction to Programming with Python

    Nov 1, 2015 · Write a while loop with a condition that is always True to draw a spiral. Interrupt the loop when the turtle reaches a certain distance from the center. Use the function turtle.distance(x, y) to get the turtle’s distance to the point defined by the coordinates x and y.

  11. Some results have been removed
Refresh