About 6,260,000 results
Open links in new tab
  1. Python while loop with string - Stack Overflow

    Jan 27, 2015 · If you wanted to loop through all characters in a string, just use a for loop: for character in myString: print(character) You can use the enumerate() function to add an index:

  2. python - string comparison in a while loop - Stack Overflow

    Apr 1, 2012 · In the second while loop you must test that count is less than len(seqA): while count < len(seqA) and seqA[count] == seqB[count]: ...

  3. While Loop - Not Equal - Python, Not Evaluating Correctly?

    Mar 13, 2018 · I'm trying to use a while loop here. It seems that the code "while (numb1 + numb2 != answer)" will always evaluate to true (even when false), and so the loop never exits. Wondering what I might have missed? Would appreciate any input!

  4. 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.

  5. Python while Loops: Repeating Tasks Conditionally

    In this tutorial, you'll learn about indefinite iteration using the Python while loop. You'll be able to construct basic and complex while loops, interrupt loop execution with break and continue, use the else clause with a while loop, and deal with infinite loops.

  6. 8 Python while Loop Examples for Beginners - LearnPython.com

    Feb 5, 2024 · In this article, we will examine 8 examples to help you obtain a comprehensive understanding of while loops in Python. Example 1: Basic Python While Loop. Let’s go over a simple Python while loop example to understand its structure and functionality: >>> i = 0 >>> while i . 5: >>> print(i) >>> i += 1 Result: 0 1 2 3 4

  7. While Loops in PythonWhile True Loop Statement Example

    Jul 19, 2022 · In this article, you will learn how to construct while loops. Here is what we will cover: What is a while loop? What is a while True loop? What is A while Loop in Python? A Definition for Beginners.

  8. 18 Python while Loop Examples and Exercises - Pythonista Planet

    Check out these examples to get a clear idea of how while loops work in Python. Let’s dive right in. 1. Example of using while loops in Python n = 1 while n < 5: print("Hello Pythonista") n = n+1 2. Example of using the break statement in while loops. In Python, we can use the break statement to end a while loop prematurely.

  9. Python While Loop - GeeksforGeeks

    Dec 10, 2024 · Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied. When the condition becomes false, the line immediately after the loop in the program is executed. In this example, the condition for while will be True as long as the counter variable (count) is less than 3.

  10. How To Construct While Loops in Python 3 - DigitalOcean

    Aug 20, 2021 · We’ll be covering Python’s while loop in this tutorial. A while loop implements the repeated execution of code based on a given Boolean condition. The code that is in a while block will execute as long as the while statement evaluates to True.

Refresh