<jupyter_start><jupyter_text>Live Lecture 3  Plan for Today- When to initialize loop counters?     - Iterator counters and global scope.- `break` and `continue`- `[*]`?  When to initialize loop counters?<jupyter_code># (A) This works, l has value "o"
# (B) This works, l has value "t"
# (C) This errors, l is not defined
# (D) This errors, can't iterate over strings. 
# (E) This runs in an infinite loop

l = "0"
while l in "to boldly go":
    print(l)
# (A) This works, i has value 0
# (B) This works, i has value 10
# (C) This errors, i is not defined
# (D) This errors, can't use variables previously 
#       defined in a while loop
# (E) This runs in an infinite loop

i = 0
while i in range(10):
    print(i)
# (A) This works, i has value 0
# (B) This works, i has value 9
# (C) This works, i has value 10
# (D) This errors, can't use variables previously defined in a while loop
# (E) This runs in an infinite loop

i = 0
while i in range(10):
    i += 1

# (A) This works, w has value "o"
# (B) This works, w has value "go"
# (C) This works, but variable w has no value. 
# (D) This errors, must define index variable prior to for loop.
# (E) This runs in an infinite loop

for w in "to boldly go".split():
    print(w)<jupyter_output>to
boldly
go<jupyter_text>`[*]`<jupyter_code># infinite loop here

# try to run some other code

# find first y in "to boldly go"

s = "to boldly go"
i = 0
while True:
    letter = s[i]
    if letter == "y":
        print("Found letter y at position " + str(i))
        break
    i += 1
# continue
s = "to boldly go"

for letter in s:
    if letter != "o":
        continue
    print(letter)<jupyter_output>o
o
o
{'fraction_non_alphanumeric': 0.11714975845410629, 'fraction_numerical': 0.010869565217391304, 'mean_word_length': 3.163316582914573, 'pattern_counts': {'":': 3, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '112792', 'license': 'MIT', 'n_tokens_mistral': 610, 'n_tokens_neox': 580, 'n_words': 267, 'path': 'live_lectures/2-lecture-exercises-sol.ipynb', 'repo_name': 'mm5110/PIC16A', 'size': '1656'}