Loops 2/19


#1
loop_condition = True

while loop_condition:
  print "I am a loop"
  loop_condition = False

I was wondering why in the while statement you don’t have to specify what boolean value loop_condition is set equal to. Does this imply that True is the default setting when checking boolean values in while loops or you simply don’t have to restate it in the while statement after you’ve already assigned a boolean value to loop_condition.


#2

We are specifying a boolean.

while loop_condition:    =>   while True:

We do not need to compare a boolean since it is one, already. Often times you might see,

while variable == True:

but it is overstating, since a == b is a boolean, just as True is.


#3

Consider the following …

a = 5
while a > 4:
  print "I am a loop"
  a = 0

When the loop is first encountered, the value of a > 4 is True, therefore the loop executes. We do not need to write …

while a > 4 == True:

In your example, @jubbjubb123, the initial value of loop_condition is True, therefore the loop executes. Similarly to the above, where a > 4 was True, we do not need to write …

while loop_condition == True:

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.