I have the following code using a for loop:
total = 0
for num in range(101):
total = total + num
print(total)
Now the
Well, for
is a special statement that automatically defines the variable for you. It would be redundant to require you to declare the variable in advance.
while
is a general purpose loop construct. The condition for a while
statement doesn't even have to include a variable; for example
while True:
or
while my_function() > 0: