Jun-03-2020, 07:09 AM
Hello All, I am learning python and I want to know the difference between while loop, do while loop, and for loop? Can anyone tell me the difference with some basic examples?
Loop In Python
|
Jun-03-2020, 07:09 AM
Hello All, I am learning python and I want to know the difference between while loop, do while loop, and for loop? Can anyone tell me the difference with some basic examples?
Jun-03-2020, 07:12 AM
How are you learning? Your learning materials should tell you the difference between them. Python doesn't have a do while loop.
Jun-03-2020, 08:36 AM
Really, just do a quick google search. You'll find dozens of different sites with Python loops and examples.
Jun-03-2020, 09:29 AM
(This post was last modified: Jun-03-2020, 09:30 AM by pyzyx3qwerty.)
In simple terms -
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela Need help on the forum? Visit help @ python forum For learning more and more about python, visit Python docs
There are different types of loops available in python ie. For loop and While loop.
There is a another function range() to create a sequence that we can use with For Loop.
@theknowshare - promoting tutorial with python 2 examples and more over not PEP8 compatible is not advisable. Please, restrain from posting with sole purpose to promote your site.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
I have found that good practice is to start with Python built-in help (help('for'), help('while'))
>>> help('while') The "while" statement ********************* The "while" statement is used for repeated execution as long as an expression is true: while_stmt ::= "while" expression ":" suite ["else" ":" suite] This repeatedly tests the expression and, if it is true, executes the first suite; if the expression is false (which may be the first time it is tested) the suite of the "else" clause, if present, is executed and the loop terminates. A "break" statement executed in the first suite terminates the loop without executing the "else" clause’s suite. A "continue" statement executed in the first suite skips the rest of the suite and goes back to testing the expression. Related help topics: break, continue, if, TRUTHVALUE (END)press q to exit help
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. |
|