F# break from while loop

后端 未结 7 2072
甜味超标
甜味超标 2021-02-18 14:30

There is any way to do it like C/C#?

For example (C# style)

for (int i = 0; i < 100; i++)
{
   if (I == 66)
       break;
} 
7条回答
  •  有刺的猬
    2021-02-18 15:28

    You have to change it to a while loop.

    let (i, ans) = (ref 0, ref -1)
    while(!i < 100 and !ans < 0) do
     if !i = 66 then
       ans := !i
    ans
    

    (This breaks when i gets to 66--but yes the syntax is quite different, another variable is introduced, etc.)

提交回复
热议问题