As you should know, in Python, the following is a valid for loop in Python:
animals = [ 'dog', 'cat', 'horse' ] # Could also be a dictionary, tuple, etc
for animal in animals:
print animal + " is an animal!"
And this is usually fine. But in my case, I want to make a for loop like the way you would in C/C++/Java etc. The for loop that looks like this:
for (int x = 0; x <= 10; x++) {
print x
}
How could I do something like this in Python? Would I have to set up something like this, or is there an actual way to do this that I'm missing (I've googled for a good few weeks):
i = 0
while i is not 10:
print i
Or is there a standard of how to do this? I find the above does not always work. Yes, for the case of the above I could do:
for i in range(10):
print i
But in my case I can't do this.
for i in range(10)?for(;;).) What C calls a FOR is nothing but a WHILE loop with weird syntax, and you can implement any C FOR loop as a WHILE loop without much difficulty.range— and "it didn't work", although "in Java it worked fine." Instead of debugging the code to find why it didn't work, you concluded that the problem is in the lack of an "actual" for loop and asked a question to that effect. The responders are answering the question you asked to the best of their ability, but that does nothing to resolve your problem, which lies elsewhere. Please find the actual problem and, if you still have a question, ask it here.