Alex Rivera | Logout

how to pause the console in F# language

Asked 2013-03-09T07:09:57.537
12

Please tell me how I can pause the console window when running the program in F#.

open System
let myList = [0..9]
let myFunction =
for n in myList do
    Console.WriteLine(n)
myFunction
f#
Edit
Report

1 Answer

1
// When running in debug mode and using Visual Studio to run the program,  
// one may miss the results as the program runs to the end and exists.  
// Since running normally, i.e. Visual Studio Ctrl-F5, will add an pause
// automatically the pause is only shown when in debug mode.  
let pause () =  
  match System.Diagnostics.Debugger.IsAttached with  
  | true ->  
      printfn "\nPress any key to continue."  
      System.Console.ReadKey(true) |> ignore  
  | false -> ()  

pause ()  
answered 2013-03-09T16:37:57.530

Your Answer