+ 1
What kind of use [for], [while] in Python?
I don't understand well.
3 odpowiedzi
+ 10
See 'for' and 'while' are loops in Python.
Loops executes the block of code until a condition is satisfied. When the condition becomes false, the statement immediately after the loop is executed.
The statements inside them are repeatedly executed, as long as the condition holds.
+ 7
'for' iterates (goes through one thing at a time) over a sequence like a list or a string or a range of numbers, and makes the loop execute each time.
'while' makes the loop execute as long as the condition is True.
e.g.
for x in "abc":
print(x)
outputs:
a
b
c
i = 0
while i < 3:
print("abc"[i])
i = i + 1
outputs:
a
b
c
+ 2
for is count controlled whereas while is condition controlled.