- 2
Can you please explain me this
4 Answers
+ 7
Loop envelopes a part of the code to run this part more than once. "For" loop runs it a specified number of times, "while" - until its condition is False.
Potential uses include: iteration over a collection variable, repeated execution of the code until user action is activated and so on.
+ 3
Use of loop in Python is not trivial, as it doesn't follow the classical model of for (initialization, test, incrementation), but rather iterate over a list...
So, you can loop over a list content, and the range() function is made with that meaning: it return a generated list of integers, from a starting to an ending value (not included), with a specific step. Default value for start is zero, default step is one... you'll be required to pass at least one parameter for the boundary ending value: range(5) == [ 0, 1, 2, 3, 4 ], while 2 parameters are expected to be start then end, and a third one added is the step value (wich can obviously be negative) ^^
+ 1
Post the code you're having trouble with.
0
for i in range(5):
print("hello!")



