F# Code Error: Unmatched Parenthesis in While Loop - Solution & Explanation
{"title":"open System\n\nlet input = Console.ReadLine()\nlet nums = input.Split(' ')\nlet num1 = Int32.Parse(nums.[0])\nlet num2 = Int32.Parse(nums.[1])\n\nlet ans = \n\tseq { num1..num2 }\n\t|> Seq.filter (fun x -> \n\t let mutable j = x\n\t let mutable containsTwo = false\n\t while j > 0 && not containsTwo do\n\t if j % 10 = 2 then\n\t containsTwo <- true\n\t j <- j / 10\n\t containsTwo // <-- Add closing parenthesis here\n\t)\n\t|> Seq.length\nprintfn "%d" ans//执行错误:\n/box/script.fsx(10,19): error FS0583: Unmatched '('内容:The code you provided has a syntax error on line 10. The opening parenthesis "(" does not have a matching closing parenthesis ")".\n\nTo fix this error, you can add a closing parenthesis after the end of the while loop, like this:\n\nfsharp\nlet ans = \n\tseq { num1..num2 }\n\t|> Seq.filter (fun x -> \n\t let mutable j = x\n\t let mutable containsTwo = false\n\t while j > 0 && not containsTwo do\n\t if j % 10 = 2 then\n\t containsTwo <- true\n\t j <- j / 10\n\t containsTwo // <-- Add closing parenthesis here\n\t)\n\t|> Seq.length\n\n\nThis will resolve the syntax error and allow the code to compile and run correctly.
原文地址: https://www.cveoy.top/t/topic/p1Ua 著作权归作者所有。请勿转载和采集!