Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 671

Does OCaml support for-each loops?

$
0
0

I would like to print each integer in a list.

I can do this with List.iter like so:

digits|> List.iter  (fun i -> print_int i; print_newline ())

However, I generally prefer to keep imperative code outside of pipelines of functions.

Is it possible to write this in a for-each loop in OCaml?

(Hypothetical syntax)

for i in digits do  print_int i ;   print_newline ()end

Viewing all articles
Browse latest Browse all 671

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>