Skip to content

Instantly share code, notes, and snippets.

@kirkdrichardson
Last active October 8, 2019 02:52
Show Gist options
  • Save kirkdrichardson/880e763c99d49f238578de39d5a49bdd to your computer and use it in GitHub Desktop.
Save kirkdrichardson/880e763c99d49f238578de39d5a49bdd to your computer and use it in GitHub Desktop.
Looping and Iteration in Dart (since v2.2)
// Looping and Iteration in Dart (since v2.2)
// No surprises here.
// This example can be run at https://dartpad.dartlang.org/880e763c99d49f238578de39d5a49bdd
// For other examples see https://gist.github.com/kirkdrichardson
void main() {
// O(n) version of n(n+1)/2 series, i.e. the sum of 1 + 2 + 3 + 4...n
int nSeriesSum = 0;
for (var i = 1; i <= 10; i++) nSeriesSum += i;
print(nSeriesSum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment