Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
void main() {
print(sum1(100));
print(sum2(100, start: 51));
print(sum3(100, start: 21, step: 3));
}
int sum1(int value) {
int result = 0;
for(int i=1; i <= value; i++) {
result += i;
}
return result;
}
int sum2(int value, {int start = 1}) {
int result = 0;
for(int i = start; i <= value; i++) {
result += i;
}
return result;
}
int sum3(int value, {int start = 1, int step = 1}) {
int result = 0;
for(int i = start; i <= value; i += step) {
result += i;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment