1,105,633 Community Members

do-while loop in python

Member Avatar
shafter111
Newbie Poster
6 posts since Feb 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi.....I am a newbie...really confused with do while loop in python. Does it even exist?

J=[]
    do:
        finished = "false"
        while finished != "true":
            finished="true"
            for j in xrange(len(lis2)):
                  cenP2 = G[i+G0]
                   if ((cenP2 == 0) & (sigma2 > 0)  
                          J.append(1)
                          finished = "false"
                          print 3 # test code never gets here
                   else:
                          finished="true"
                         print 4

Sorry, I left out a few details caz its not important and just takes up space. My point is....how do I do this? I know this is not right, but is there a way?

Thanks a lot .....

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 

No, there is no "do ... while" loop in Python. A properly constructed while loop can do the same.

If you have any problems, give us a simplified idea of what you want to accomplish. We will be glad to help!

Member Avatar
teci
Newbie Poster
2 posts since Jun 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

from //kogs-www.informatik.uni-hamburg.de/~meine/python_tricks

while True:
    do_something()
    if condition():
        break

Godspeed :)

Editors note:
For Python code on Daniweb:
Please use the [code=python] and [/code] tag pair to enclose your python code.

Member Avatar
wanne
Newbie Poster
2 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

I have a doubt in while loop that suppose i want to do one looping process to assign values, how I have to do.
For example:
Having one list like L1 =
need to do pop operation and assign value like,
z1 = L1.pop()
z2 = L2.pop()
z3 = L3.pop()
...
similarly upto length of the list. Please give a solution.

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 

Please do not hijack old threads, start your own new thread!

Question Answered as of 4 Years Ago by vegaseat, teci and wanne
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article