Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Last active January 30, 2020 04:48
Show Gist options
  • Select an option

  • Save IhwanID/c51260e501813908b6b882474109ff14 to your computer and use it in GitHub Desktop.

Select an option

Save IhwanID/c51260e501813908b6b882474109ff14 to your computer and use it in GitHub Desktop.
looping
void main() {
List<int> numbers = [1, 2, 3, 4, 5];
print(total(numbers));
print(combine(numbers));
}
int total(List<int> value){
int i = 0;
int result = 0;
while(i < value.length){
result += value[i];
i++;
}
return result;
}
int combine(List<int> values){
return values.fold(0, (result, value) => result + value);
}
int sum(List<int> values){
int result = 0;
for(int i = 0; i < values.length; i++){
result += values[i];
}
//simple
for(int value in values){
result += value;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment