Last active
October 8, 2019 02:52
-
-
Save kirkdrichardson/880e763c99d49f238578de39d5a49bdd to your computer and use it in GitHub Desktop.
Looping and Iteration in Dart (since v2.2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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