To create a list of numbers from 1 to N in Dart, you can use a List
In this example,
numbers
and use a for loop to add numbers from 1 to N.void main() {
int N = 5;
List<int> numbers = [];
for (int i = 1; i <= N; ++i) {
numbers.add(i);
}
print('List of numbers from 1 to $N: $numbers');
}
List of numbers from 1 to 5: [1, 2, 3, 4, 5]
In this tutorial, we learned How to create a List of Numbers from 1 to N in Dart language with well detailed examples.