Try to search your question here, if you can't find : Ask Any Question Now ?

Why does the 'while true' loop cause an infinite loop?

HomeCategory: stackoverflowWhy does the 'while true' loop cause an infinite loop?
gaurav asked 4 days ago

I understand the basic concept of the ‘while loop’. But I do not understand why this particular code containing ‘while true’ causes an infinite loop.

condition = 1

while condition < 10: 
    print(condition)   
    condition += 1

while True:
    print('hello word')

I understand when we start with condition = 1, it is less than 10, so that is is ‘true’. But when we get to condition = 11, doesn’t the statement become false (as 10 is less than 11?). When I run this code, it print hello world forever until the compiler crashes. Why does it keep going? Shouldn’t it stop when the condition = 11? And also, why does the print(condition) no longer show up when I do this?

1 Answers
Best Answer
Fernando answered 4 days ago
Your Answer

3 + 1 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com