在foreach循环中使用if语句

ace*_*007 1 erlang

我似乎总是在同一代码块中使用2个“ end”的问题,例如:

 Worker = fun (File) ->
 {ok, Device} = file:read_file([File]),
 Li = string:tokens(erlang:binary_to_list(Device), "\n"),
 Check = string:join(Li, "\r\n"),
 FindStr = string:str(Check, "yellow"),
 if
  FindStr > 1 -> io:fwrite("found");
  true -> io:fwrite("not found")
 end,
end,
Run Code Online (Sandbox Code Playgroud)

消息是“语法错误之前:'结束'”

小智 5

您需要删除两端之间的逗号。

Worker = fun (File) ->
 {ok, Device} = file:read_file([File]),
 Li = string:tokens(erlang:binary_to_list(Device), "\n"),
 Check = string:join(Li, "\r\n"),
 FindStr = string:str(Check, "yellow"),
 if
  FindStr > 1 -> io:fwrite("found");
  true -> io:fwrite("not found")
 end
end,
Run Code Online (Sandbox Code Playgroud)