0
0
Blockchain / Solidityprogramming~20 mins

Using for directive in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
For Directive Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple for directive loop
What is the output of this blockchain smart contract snippet using a for directive to iterate over transactions?
Blockchain / Solidity
let total = 0;
for (let i = 0; i < 3; i++) {
  total += i * 10;
}
console.log(total);
A30
B60
C0
DSyntaxError
Attempts:
2 left
💡 Hint
Remember the loop runs from 0 to 2, adding i*10 each time.
🧠 Conceptual
intermediate
1:30remaining
Understanding for directive in blockchain event processing
In a blockchain smart contract, which best describes the purpose of a for directive when processing a list of events?
ATo repeat actions for each event in the list sequentially
BTo execute only the first event and skip the rest
CTo randomly select events to process
DTo permanently stop the contract execution
Attempts:
2 left
💡 Hint
Think about how loops help handle multiple items.
🔧 Debug
advanced
2:00remaining
Identify the error in this for directive code
What error does this blockchain smart contract code produce?
Blockchain / Solidity
for (let i = 0; i < 5; i++) {
  console.log(i);
}
AReferenceError because console is undefined
BTypeError because i is not defined
CSyntaxError due to missing parentheses in for loop
DNo error, prints numbers 0 to 4
Attempts:
2 left
💡 Hint
Check the syntax of the for loop header.
Predict Output
advanced
2:30remaining
Output of nested for directives in blockchain code
What is the output of this nested for directive code snippet?
Blockchain / Solidity
let result = '';
for (let i = 1; i <= 2; i++) {
  for (let j = 1; j <= 2; j++) {
    result += `${i}${j} `;
  }
}
console.log(result.trim());
A"1 2 1 2"
B"12 11 22 21"
C"SyntaxError"
D"11 12 21 22"
Attempts:
2 left
💡 Hint
The outer loop controls the first digit, inner loop the second.
🚀 Application
expert
3:00remaining
Calculating total token transfers using for directive
Given this blockchain code snippet that sums token transfers, what is the final value of totalTokens?
Blockchain / Solidity
const transfers = [100, 200, 50, 150];
let totalTokens = 0;
for (const amount of transfers) {
  if (amount > 100) {
    totalTokens += amount;
  }
}
console.log(totalTokens);
A500
B350
C100
DSyntaxError
Attempts:
2 left
💡 Hint
Add only amounts greater than 100.