🌐
W3Schools
w3schools.com › python › python_while_loops.asp
Python While Loops
Python Examples Python Compiler ... Certificate Python Training ... With the while loop we can execute a set of statements as long as a condition is true....
🌐
Real Python
realpython.com › python-while-loop
Python while Loops: Repeating Tasks Conditionally – Real Python
March 3, 2025 - 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.
Discussions

Whats the difference between a while loop and a for loop?
Consider how the terms are used in common language: FOR For each day in July, I will practice writing loops. For every student in the class, provide a lunchtime meal. For each letter in the alphabet, write down a word beginning with that letter. For numbers in the range 1 to 10, calculate the square root. Notice that for each case, we iterate through multiple things (days in the month / students in the class / letters in the alphabet / numbers in a range). WHILE While there is still daylight, we can play football. While the music is playing, we will dance. While I am waiting, I will read a book. While my set of Pokémon cards is incomplete, I will keep collecting them. Notice that in each case, something is done for as long as a condition (a "predicate") is satisfied (is "True"). In these examples, the predicates are: "There is daylight?", "The music is playing?", "I am waiting?", "The set is incomplete?". As soon as the answer is "False", the loop stops. More on reddit.com
🌐 r/learnpython
69
124
July 15, 2024
Reddit
I've been writing Python scripts for a while now. Nothing crazy, just automating small stuff, scraping some data, making my life a little easier. I thought I had a decent handle on things. I was looking at someone else's code and they used a list comprehension in a way that made me stop and read it three times. I realized I had been writing loops ... More on reddit.com
🌐 r/learnpython
October 29, 2018
Python While Loop

If you want to modify a global from within a function scope you need to use global in the function (basically saying "use the upper scope instead of local"). Generally though try to avoid globals as good programming style.

Example demonstrating this:

global test

def set_true_local():
test = True

def set_true_global():
global test # Use global version of test
test = True

test = False
print('Before: {}'.format(test)) # False

set_true_local()
print('After set_true_local: {}'.format(test)) # False

set_true_global()
print('After set_true_global: {}'.format(test)) # True
More on reddit.com
🌐 r/AskProgramming
7
5
July 5, 2015
I've trying to learn while loops for over 2 weeks... Help? [ELI5]

You have two variables, m and c. The variable m is what the user inputs to determine what height the ball is dropped from. The variable c will count the number of bounces.

Then the while loop starts. Quite literally, while the ball bounces back to a height that is greater than 0.01, your program keeps executing the rest of the code over and over.

In this specific case, your program first decreases the height to 70% of previous value (so it bounces back lower due to gravity), then increments the c counter by one, so says the ball bounces one time.

Then the instruction in the while loop is over. The program checks again if the height m is greater than 0.01. If it is, it will keep repeating the while loop code block until the condition is no longer met. If it isn't, it will do the rest of the code. In this example it will print that the ball has bounced c number of times.

You print c because that is the variable where you store number of bounces. If you printed m it would print the height the ball is at right now, after all those operations. Which would mean it would print a number that's less than 0.01.

More on reddit.com
🌐 r/learnpython
10
3
February 19, 2018
People also ask

Q1. What is while loop in Python?
Ans: Python while loop keeps on executing a block of code as long as the condition within the while loop remains true.
🌐
pwskills.com
pwskills.com › blog › python › python while loops: complete tutorial for beginners
Python While Loops: Complete Tutorial For Beginners
Q3. Can we use else with While loop in Python?
Ans: Yes, we can use the else conditional statement with the while loop when we need to evaluate a condition after an iteration or complete while loop gets completed.
🌐
pwskills.com
pwskills.com › blog › python › python while loops: complete tutorial for beginners
Python While Loops: Complete Tutorial For Beginners
Q4. How to stop the infinite while loop in Python?
Ans: You can use the break statement in Python to stop the infinite in Python.
🌐
pwskills.com
pwskills.com › blog › python › python while loops: complete tutorial for beginners
Python While Loops: Complete Tutorial For Beginners
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-while-loop
Python While Loop - GeeksforGeeks
Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied.
Published   December 23, 2025
🌐
DataCamp
campus.datacamp.com › courses › introduction-to-python-for-developers › control-flow-and-loops-3
While loops | Python
We start a while loop with the while keyword followed by a condition and end the line with a colon. The next line is indented and contains the action to perform while the condition is met. While loops are useful for continuous tasks.
🌐
PW Skills
pwskills.com › blog › python › python while loops: complete tutorial for beginners
Python While Loops: Complete Tutorial For Beginners
November 4, 2025 - Python while loop can be used to execute a block of statement repeatedly until the condition evaluates to true. Let us learn more about Python while loops in this blog.
🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-between-for-loop-and-while-loop-in-python
Difference between for loop and while loop in Python - GeeksforGeeks
September 11, 2025 - For loop can iterate over any iterable object, such as dictionary, list or any custom iterators. ... Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied.
Find elsewhere
🌐
BrainStation®
brainstation.io › learn › python › while-loop
Python While Loop (2026 Tutorial & Examples) | BrainStation®
February 4, 2025 - Python While Loops are a very clever way to run or execute a block of code multiple times with different values. This allows you to write the logic only once…
🌐
Substack
adlrocha.substack.com › p › adlrocha-auto-research-the-lab-that
@adlrocha - Auto-research: The Lab that runs while you sleep
2 weeks ago - Karpathy’s choice of that metric, rather than something noisier, slower, or more expensive, is a big part of why the system works at all. Even more, the fact that the runs are limited to 5 minutes provides a fast feedback loop to the agents that allows them to iterate fast and understand the impact of their changes.
🌐
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu › notebooks › chapter05.02-While-Loops.html
While Loops — Python Numerical Methods
The code is released under the MIT license. If you find this content useful, please consider supporting the work on Elsevier or Amazon! ... A while loop or indefinite loop is a set of instructions that is repeated as long as the associated logical expression is true.
🌐
freeCodeCamp
freecodecamp.org › news › python-do-while-loop-example
Python Do While – Loop Example
August 31, 2021 - The while loop, on the other hand, doesn't run at least once and may in fact never run. It runs when and only when the condition is met. So, let's say we have an example where we want a line of code to run at least once. secret_word = "python" counter = 0 while True: word = input("Enter the secret word: ").lower() counter = counter + 1 if word == secret_word: break if word != secret_word and counter > 7: break
🌐
Go
go.dev › doc › effective_go
Effective Go - The Go Programming Language
There is no do or while loop, only a slightly generalized for; switch is more flexible; if and switch accept an optional initialization statement like that of for; break and continue statements take an optional label to identify what to break or continue; and there are new control structures ...
🌐
Reddit
reddit.com › r/learnpython › whats the difference between a while loop and a for loop?
r/learnpython on Reddit: Whats the difference between a while loop and a for loop?
July 15, 2024 -

I want to ask, whats the difference between looping using the while and the for function? I know both of these functions loops through stuff but what exactly is the difference between them? I have trouble understanding so I decide to ask this question on here

🌐
The Knowledge Academy
theknowledgeacademy.com › blog › python-while-loop
Python While Loop: Everything You Should Know
1 month ago - A Python While Loop repeatedly executes a block of code as long as a specified condition is true, and stops only when the condition becomes false.
🌐
Programiz
programiz.com › python-programming › while-loop
Python while Loop (With Examples)
In Python, we use a while loop to repeat a block of code until a certain condition is met.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-do-while
Python Do While Loops - GeeksforGeeks
July 23, 2025 - In Python, we can simulate the behavior of a do-while loop using a while loop with a condition that is initially True and then break out of the loop when the desired condition is met.
🌐
Altcademy
altcademy.com › blog › what-is-a-while-loop-in-python
What is a while loop in Python
January 31, 2024 - A while loop in Python is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The code block will keep running over and over as long as the condition is true.
🌐
GeeksforGeeks
geeksforgeeks.org › python › loops-in-python
Loops in Python - GeeksforGeeks
In Python, a while loop is used to execute a block of statements repeatedly until a given condition is satisfied.
Published   1 week ago
🌐
Python documentation
docs.python.org › 3 › tutorial › introduction.html
3. An Informal Introduction to Python — Python 3.14.3 documentation
The while loop executes as long as the condition (here: a < 10) remains true. In Python, like in C, any non-zero integer value is true; zero is false. The condition may also be a string or list value, in fact any sequence; anything with a non-zero length is true, empty sequences are false.
🌐
Tutedude
tutedude.com › category › python
Learn Python: Start Your Programming Journey with Tutedude
Learn Python with Tutedude's structured curriculum, instant doubt resolution, and hands-on projects. Enjoy lifetime access and a full refund upon completion.
🌐
ScholarHat
scholarhat.com › home
Loops in Python - For, While loop (With Examples)
September 10, 2025 - To understand the Loop Structures in Python, you need to know that there are 3 Types of Loops in Python: ... A while loop in Python is used to repeat a block of code as long as a certain condition is true.