GeeksforGeeks
geeksforgeeks.org โบ python โบ python-do-while
Python Do While Loops - GeeksforGeeks
July 23, 2025 - In this code output, we can see that- The Do While loop is terminated, because the condition len(list1[5])<10 is not fulfilling. Printing list items using while loop geeksforgeeks C++ Java Python C MachineLearning Printing list items using do while loop geeksforgeeks C++ Java Python C
GeeksforGeeks
geeksforgeeks.org โบ python โบ loops-in-python
Loops in Python - GeeksforGeeks
... Note: It is suggested not to ... have to forcefully terminate the compiler. Python programming language allows to use one loop inside another loop which is called nested loop....
Published ย June 7, 2017
Videos
GeeksforGeeks
geeksforgeeks.org โบ python โบ python-while-loop
Python While Loop - GeeksforGeeks
When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements. Python Continue Statement returns the control to the beginning of the loop. ... # Prints all letters except 'e' and 's' i = 0 a = 'geeksforgeeks' while i < len(a): if a[i] == 'e' or a[i] == 's': i += 1 continue print(a[i]) i += 1
Published ย December 23, 2025
GeeksforGeeks
geeksforgeeks.org โบ python โบ how-to-emulate-a-do-while-loop-in-python
How to Emulate a Do-while loop in Python? - GeeksforGeeks
July 23, 2025 - Do while loop is a type of control looping statement that can run any statement until the condition statement becomes false specified in the loop. In do while loop the statement runs at least once no matter whether the condition is false or true.
EDUCBA
educba.com โบ home โบ software development โบ software development tutorials โบ python tutorial โบ do while loop in python
Do While Loop in Python | Emulate Do While Loop in Python(Example)
March 17, 2023 - If the value of the i =1, then ... a break statement, which if loop stops. In the python body of the while, the loop is determined through indentation....
Call ย +917738666252
Address ย Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Scaler
scaler.com โบ home โบ topics โบ python do while loop
Python Do While Loop - Scaler Topics
December 1, 2023 - Since Python does not explicitly provide its do-while Loop (like C and C++ do), we will have to make a workaround using the existing loops in Python, for-loop, and while-loop. But first, let us look at the control flow for the do-while Loop. A do-while loop in a logic flow diagram (or a flow chart) looks as follows:
GeeksforGeeks
geeksforgeeks.org โบ loops-in-python
Loops in Python - For, While and Nested Loops - GeeksforGeeks
In this article, we will look at Python loops and understand their working with the help of examples. In Python, a while loop is used to execute a block of statements repeatedly until a given condition is satisfied.
Published ย March 8, 2025
W3Schools
w3schools.com โบ python โบ python_while_loops.asp
Python While Loops
With the break statement we can stop the loop even if the while condition is true: ... Note: The else block will NOT be executed if the loop is stopped by a break statement. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Top answer 1 of 16
1331
I am not sure what you are trying to do. You can implement a do-while loop like this:
while True:
stuff()
if fail_condition:
break
Or:
stuff()
while not fail_condition:
stuff()
What are you doing trying to use a do while loop to print the stuff in the list? Why not just use:
for i in l:
print i
print "done"
Update:
So do you have a list of lines? And you want to keep iterating through it? How about:
for s in l:
while True:
stuff()
# use a "break" instead of s = i.next()
Does that seem like something close to what you would want? With your code example, it would be:
for s in some_list:
while True:
if state is STATE_CODE:
if "//" in s:
tokens.add( TOKEN_COMMENT, s.split( "//" )[1] )
state = STATE_COMMENT
else :
tokens.add( TOKEN_CODE, s )
if state is STATE_COMMENT:
if "//" in s:
tokens.append( TOKEN_COMMENT, s.split( "//" )[1] )
break # get next s
else:
state = STATE_CODE
# re-evaluate same line
# continues automatically
2 of 16
413
Here's a very simple way to emulate a do-while loop:
condition = True
while condition:
# loop body here
condition = test_loop_condition()
# end of loop
The key features of a do-while loop are that the loop body always executes at least once, and that the condition is evaluated at the bottom of the loop body. The control structure show here accomplishes both of these with no need for exceptions or break statements. It does introduce one extra Boolean variable.
Tutorialspoint
tutorialspoint.com โบ python โบ python_while_loops.htm
Python - While Loops
If it fails to turn false, the loop continues to run, and doesn't stop unless forcefully stopped. Such a loop is called infinite loop, which is undesired in a computer program. The syntax of a while loop in Python programming language is โ ... In Python, all the statements indented by the same number of character spaces after a programming construct are considered to be part of a single block of code. Python uses indentation as its method of grouping statements. The following flow diagram illustrates the while loop โ
Programiz
programiz.com โบ python-programming โบ while-loop
Python while Loop (With Examples)
If the condition is True, body of while loop is executed. The condition is evaluated again. This process continues until the condition is False. Once the condition evaluates to False, the loop terminates.
ScholarHat
scholarhat.com โบ home
Python While Loop - Flowchart, Syntax with Example
September 11, 2025 - The execution will take place till the 'if' condition is evaluated to be true, then it will terminate the loop completely and proceeds to the first statement following the loop. ... It will evaluate the 'if' condition and when it turns out to be true, the execution of that value will be skipped continuing to the next one. ... It will simply skip the preceding block of code. A Python while loop can have an optional else clause.
GeeksforGeeks
geeksforgeeks.org โบ dsa โบ difference-between-for-while-and-do-while-loop-in-programming
Difference between For, While and Do-While Loop in Programming - GeeksforGeeks
July 23, 2025 - A Do-While loop runs at least once and then continues if a condition is true.