0

I am new to object oriented from Bash. I have a very simple question that I having difficulty phrasing in Google or here on Stack Overflow.

How do I indicate the end of a for loop? The examples I have seen do not have a "Done" (from what I am used to in Bash). How would I run through this code until the last character is output? How do I then add more code without the program being included in the for loop?

for i in ['a', 'b', 'c', 'd']:
    print i
0

1 Answer 1

7

Simply don't indent the code you want to be outside of your loop. Python is white-space sensitive.

for i in ['a', 'b', 'c', 'd']:
    print i

# The code at this indentation is not part of the above block.
print 42
Sign up to request clarification or add additional context in comments.

1 Comment

With the addendum that continue and break statements can be used to skip an element that is being looped over or exit the loop if necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.