Logo

Programming-Idioms

Create the list r of size n and initialize it with the integers 0, 1, ..., n-1.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
r := make([]int, n)
for i := range n {
	r[i] = i
}
var
  r: array of integer;
  n, i: integer;
....
  SetLength(r,n);
  for i := 0 to n-1 do r[i] := i;
r = list(range(n))
r = (0...n).to_a
let r: Vec<i32> = (0..n).collect();