Even Number Total
Part of the Fundamentals section of Coddy's Solidity journey. Lesson 35 of 53.
Challenge
MediumUse a loop to sum the even integers from 1 through n, skipping odd values with continue. Print the final sum. n is between 0 and 20.
The tests pass arguments to main in this order: uint256 n. Each test starts with fresh contract state.
Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.
Try it yourself
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
function main(uint256 n) external view {
// Write your solution here.
}
}All lessons in Fundamentals
Practice on your own: Solidity playground