I want to do something like the following:
while myFunc() as myVar:
print myVar
Basically, just call a function in the loop line that will return a value and continue the loop depending on that value, but I would also like to be able to use that value within the loop and I would rather not have to call the function a 2nd time.
What I would like to avoid:
while myFunc():
myVar = myFunc()
print myVar
You can accomplish this using the two-argument version of the
iter()built-in function:This is equivalent to the following:
From the docs for
iter():