F# break from while loop -


there way c/c#?

for example (c# style)

for( int i=0; i<100; i++) {    if(i==66)     break; }  

the short answer no. use higher-order function express same functionality. there number of functions let this, corresponding different patterns (so if describe need, might give better answer).

for example, tryfind function returns first value sequence given predicate returns true, lets write this:

seq { 0 .. 100 } |> seq.tryfind (fun ->   printfn "%d"   i=66) 

in practice, best way go if expressing high-level logic , there corresponding function. if need express break, can use recursive function:

let rec loop n =    if n < 66      printfn "%d" n     loop (n + 1)  loop 0       

a more exotic option (that not efficient, may nice dsls) can define computation expression lets write break , continue. here example, said, not efficient.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -