Traversal Forward and Backward
📖 Scenario: Imagine you have a list of daily temperatures recorded in order. You want to look at these temperatures both from the start to the end (forward) and from the end back to the start (backward) to understand the pattern.
🎯 Goal: You will create a list of temperatures, then write code to traverse this list forward and backward, printing the temperatures in both directions.
📋 What You'll Learn
Create a list called
temperatures with exact values: [23, 25, 21, 19, 22]Create a variable called
length that stores the length of the temperatures listUse a
for loop with variable i to traverse temperatures forward from index 0 to length - 1Use a
for loop with variable i to traverse temperatures backward from index length - 1 to 0Print the temperatures in forward order separated by spaces
Print the temperatures in backward order separated by spaces
💡 Why This Matters
🌍 Real World
Traversing data forward and backward is useful in many real-life situations like reading sensor data, browsing history, or undo-redo operations.
💼 Career
Understanding how to move through data structures in both directions is a fundamental skill for software developers, data analysts, and anyone working with ordered data.
Progress0 / 4 steps