"""
Topic: Control Flow (Loops): Looping Through Strings
Purpose: Learn how to iterate over characters in a string
Output: Shows how Python processes strings one character at a time
"""
# -----------------------------
# 1. Example string
# -----------------------------
text = "Python"
# -----------------------------
# 2. Basic loop through a string
# -----------------------------
# Each iteration gives one character
for char in text:
print(char)
# -----------------------------
# 3. Using index while looping
# -----------------------------
# range() with len() to access positions
for i in range(len(text)):
print("Index:", i, "Character:", text[i])
# -----------------------------
# 4. Conditional logic while looping
# -----------------------------
# Checking specific characters
for char in text:
if char.lower() == "o":
print("Found letter o")
else:
print(char)
# -----------------------------
# 5. Counting characters
# -----------------------------
# Count vowels in a string
vowels = "aeiou"
count = 0
for char in text.lower():
if char in vowels:
count += 1
print("Number of vowels:", count)
# -----------------------------
# 6. Notes
# -----------------------------
# 1. Strings are iterable in Python.
# 2. Loops process strings character by character.
# 3. 'len()' gives the length of a string.
# 4. Strings are zero-indexed.
# 5. Looping through strings is common in text processing.