Ask Your Question
0

Is it possible to create infinite loops using for loop in Python?

asked 2023-07-01 14:31:29 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-01 14:52:01 +0000

pufferfish gravatar image

Yes, it is possible to create infinite loops using a for loop in Python. However, it is not recommended to do so as it can cause the program to hang or crash. An example of an infinite loop using a for loop is as follows:

for i in range(0,1):
    print(i)

This loop will print out the value 0 and then continue indefinitely, as the range function will always return a list of one item, and the loop will never exit.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-01 14:31:29 +0000

Seen: 7 times

Last updated: Jul 01 '23