Counting Blocks with For and While Loops
📖 Scenario: Imagine you are working with a simple blockchain that stores blocks as numbers. You want to count and display blocks using loops.
🎯 Goal: Build a program that uses both for and while loops to count blocks in a blockchain.
📋 What You'll Learn
Create a list called
blocks with the numbers 1 to 5Create a variable called
count and set it to 0Use a
for loop with variable block to iterate over blocks and increase count by 1 each timeUse a
while loop to print numbers from 1 up to count💡 Why This Matters
🌍 Real World
Counting blocks or transactions is common in blockchain programs to track progress or verify data.
💼 Career
Understanding loops is essential for blockchain developers to process data efficiently and automate tasks.
Progress0 / 4 steps