首页 > 代码库 > Erlang 两层循环控制

Erlang 两层循环控制

1、举例,比方说我想取出横坐标0-900 纵坐标0-400的坐标范围:
do_all_pos()->
do_all_pos([],0,0).

do_all_pos(Result,Length,Height)when Length<900 andalso Height=<400->
NewResult=[{Length,Height}|Result],
NewLength=Length+100,
do_all_pos(NewResult,NewLength,Height);
do_all_pos(Result,Length,Height) when Length=:=900 andalso Height<400->
NewResult=[{Length,Height}|Result],
NewHeight=Height+100,
NewLength=0,
do_all_pos(NewResult,NewLength,NewHeight);
do_all_pos(Result,Length,Height) when Length=:=900 andalso Height=:=400->
[{Length,Height}|Result].

2、如果是三维坐标求法,则直接在外层调用,不建议用三个函数参数变量来控制

Erlang 两层循环控制