Using for directive in blockchain smart contract
📖 Scenario: You are creating a simple blockchain smart contract that manages a list of registered users. You want to loop through the list of users to check their status.
🎯 Goal: Build a smart contract that stores a list of users and uses a for directive to iterate over them to count how many are active.
📋 What You'll Learn
Create a list variable called
users with exact entries: 'Alice', 'Bob', 'Charlie'Create a dictionary called
status with exact entries: 'Alice': True, 'Bob': False, 'Charlie': TrueUse a
for directive with variable user to iterate over usersCount how many users have
True status in statusPrint the count with the exact text:
Active users: X where X is the count💡 Why This Matters
🌍 Real World
Smart contracts often need to process lists of users or transactions. Using loops helps automate checks and calculations.
💼 Career
Blockchain developers use loops and data structures to manage user states, balances, and permissions efficiently in smart contracts.
Progress0 / 4 steps