''' While loops '''

num = 2
while num <= 10:
    num = num * 2
    #print(num)

num = 5
while num <= 10:
    num = num * 2
    #print(num)


## Infinite loops:
# what happens when your condition never becomes False
#while True:
    #n = 1
    #print('It never ends')
    
num = 3    
#while num <= 10:
    ##forgetting to update n can also lead to an infinite loop
    #print(num)

# Remember how we itereated over strings with for loops
#s = 'hello'
#for char in s:
    #print(char)

# each of the characters has an index in the string (0, 1, 2, etc.)
#print(s[0])
#print(s[1])
#print(s[2])
      
# so we can use these indexes as part of our while condition
# Let's print out all characters up to the first vowel
s = 'xyz'
i = 0
# we need i < len(s) so that s[i] does not cause an error if i 
# is not a proper index of s
while (i < len(s)) and not (s[i] in 'aeiouAEIOU'):
    print(s[i])
    i = i + 1 # we have to change i or we get an infinite loop


def up_to_vowel(s: str) -> str:
    """Return a substring of s from index 0 up to but not 
    including the first vowel in s.
    
    >>> up_to_vowel('hello')
    'h'
    >>> up_to_vowel('there')
    'th'
    >>> up_to_vowel('cs')
    'cs'
    """
    before_vowel = '' # an accumulator variable

    i = 0

    while (i < len(s)) and not (s[i] in 'aeiouAEIOU'):
        before_vowel = before_vowel + s[i]
        i = i + 1
    
    return before_vowel

