# understand that body of this while loop never executes!
#
def whileFn():
    output = "Hello!"
    while False:
        print(output)
    print("All done!")

# understand that this loop never terminates! "All done!" will never print
#
def whileFn2():
    output = "Hello!"
    while True:
        print(output)
    print("All done!")


# while loops are often used to handle user-interaction loops
#
def whileFn3():
    userText = input("Type some text ('q' to quit): ")
    while userText != 'q':
        
        print("The user entered: ", userText)
        
        userText = input("Type some text ('q' to quit): ")
    print("Goodbye!")
    
# with "while != 0" not-very-careful testing might lead to conclusion that this
# code works.
# countDownBy3From(3) prints just 3 (and 'all done'),
# countDownBy3From(18) prints 18 15 12 9 6 3 (and 'all done')
# But what positive numbers cause problems?
# Fix with "current > 0" instead of "current != 0"
#
def countDownBy3From(number):
    
    current = number
    
    while current != 0:
        
        print(current)
        
        current = current - 3
        
    print("all done")

# demonstrate general pattern for iterating through characters
# of a string using while
#
def loopChars(inputString):
    result = ""
    
    currentIndex = 0
    while currentIndex < len(inputString):
        
        currentChar = inputString[currentIndex]

        #print(currentChar, currentIndex)
        
        #
        # body of loop - typically do some computation
        # using character currentChar
        #
        # For example:
        result = result + currentChar + currentChar 
        print("result so far", result)
        
        currentIndex = currentIndex + 1

    return result

    



