What you have written is okay, but if I were doing it I'd have probably used some of the library function to replace some of the control flow you are using. Here is my effort:

1
2
3
4
5
6
7
8
9
10
11
12
#light
// create infinte list of all integers
let ints = IEnumerable.init_infinite (fun x -> x)

// interate over the list of integers
ints
|> IEnumerable.iter 
    (fun x -> 
        if System.Console.KeyAvailable && System.Console.ReadKey().KeyChar = 'q' then
            exit 0
        System.Console.WriteLine(x))
By on 9/26/2006 8:17 AM ()

Since the training exercises are definitely in the world of imperative programming, its also OK just to use a while loop with a reference cell for the counter:

1
2
3
4
5
6
7
8
9
10
11
 

#light

open System
let count = ref 0
while not (Console.KeyAvailable && (Console.ReadKey().Key = ConsoleKey.Escape))  do
    Console.WriteLine(!count);
    incr count
Console.WriteLine("end")

Don

By on 9/26/2006 10:43 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper