''' Purpose: introduce looping. the program processes the characters in a string one-by-one. ''' # get user's name name = input( "Enter first name: " ) # print the letters in the name one-by-one print( 'Loop starting' ) for current_letter in name : # name is a string and the value of the loop variable current_letter is each character in name print( 'Loop repeating with loop variable: ', current_letter ) # prints out current loop variable value (character in name) # process the current letter by printing it uppercase_letter = current_letter.upper() # Capitalize each letter one at a time print(uppercase_letter) # print out each capitalized letter one at a time print( 'Loop done' ) # Notice how statements that aren't indented into the for loop are only done once! # It prints 'Loop starting' and 'Loop done' once since they're not in the for loop. # The other print statements on lines 13 and 16 are in the loop so they're repeated for # each new value of the for loop loop variable! (each character in the string name)) # Statements are repeated in the loop if they're indented inside the loop. # If the print statement is on the outside and you're printing the value of the loop variable, # it will print the last value the loop variable takes on (the last character in this string in this example)