Infinite loop problems.
Used this code:
To write an infinite loop, use True as the condition:
while (True):
i = getInput()
print("input is",i)
process(i)
Got this error:
Traceback (most recent call last):
File "/Users/nfsiddiqui/Documents/whileloop.py", line 18, in
It is saying that you never defined a function called getInput(). That example is using a non-standard function.
As a standard function, if it was for user input, you would use raw_input() or input() in python2.x, and input() or eval(input()) in python3.x. For the example listed, I would do something different. The goal is to show you an infinite loop, which is a BAD thing to make. An easy one is this: i=0 while (True): i = i+1 print(i) Note, the above code is python 3.x code. I can tell because of the () around what you are printing. In 2.x, it woull be slightly different.
And you use control-c to stop it when you get tired of seeing numbers whiz by.
Thanks, just tried your infinite loop and it worked. The commands get input, raw input, eval input...do they change every time a new version of python is released? Or am I not understanding what they are for?
2.x has flaws. 3.x is a major overhaul, but they don't expect full implementation for about another year or two. So at this point 2.x is still more popular, but 3.x is very popular. They gave a 5 year plan for the change over, and it is 4 years in....
Join our real-time social learning platform and learn together with your friends!