This while loop prints each letter of the word 'banana' on a separate line.

PHOTO EMBED

Thu Sep 22 2022 00:54:08 GMT+0000 (Coordinated Universal Time)

Saved by @L0uJ1rky45M #python

fruit = 'banana'
index = 0
while index < len(fruit):
    letter = fruit[index]
    print(letter)
    index = index + 1

#output
b
a
n
a
n
a
content_copyCOPY

This pattern of processing is called a traversal where the program starts at the beginning, selects each character in turn, does something to it, and continues until the end. The loop condition is index < len(fruit). When index == length of the string, the condition is false, and the body of the loop is not executed. The last character accessed is the one with the index len(fruit)-1, which is the last character in the string.

https://www.py4e.com/html3/06-strings