> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/h/harshad_or_niven_series.md).

# Harshad or Niven series

```ruby
func harshad() {
    var n = 0
    {
        ++n while !n.digits.sum.divides(n)
        n
    }
}

var iter = harshad()
say 20.of { iter.run }

var n
do {
    n = iter.run
} while (n <= 1000)

say n
```

#### Output:

```
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42]
1002
```
