In: Computer Science
What would be the output of the following?
autocorrectisawful = 4
while (autocorrectisawful > 0):
print(autocorrectisawful)
if (autocorrectisawful == 2):
break
autocorrectisawful -= 1
As indentation was missing in question i assume this was the actual indentation(given below).
it's output will be (explanation given below):
Explanation :
1) at first value of autocorrectisawful will be 4, so while condition will result into true and it will print value of autocorrectisawful on screen which is 4 ,if (autocorrectisawful == 2) will result into false and decrement value of autocorrectisawful by 1 , so value of autocorrectisawful will be 3.
2)second time value of autocorrectisawful will be 3 still while condition will result into true and print 3 then if (autocorrectisawful == 2) will result into false as autocorrectisawful is 3 then at the end by decrementing value of autocorrectisawful by 1, so value of autocorrectisawful will be 2 now.
3) third time value of autocorrectisawful will be 2 while condition will result into true and print 2 then if (autocorrectisawful == 2) will result into true as autocorrectisawful is 2 and execute break statement which will exit while loop.