Skip to content

Instantly share code, notes, and snippets.

@cleanunicorn
Created April 8, 2021 15:17
Show Gist options
  • Select an option

  • Save cleanunicorn/894620e8eebcf8093f06ff9b985747bf to your computer and use it in GitHub Desktop.

Select an option

Save cleanunicorn/894620e8eebcf8093f06ff9b985747bf to your computer and use it in GitHub Desktop.
contract A {
uint[10] list = [1,2,3,4,5,6,7,8,9,10];
function loop(uint _n) public view returns (uint) {
uint sum = 0;
uint start = list.length - 1;
uint end = list.length - _n;
for (uint i = start; i >= end; i--) {
sum += list[i];
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment