calculateSum(_, _List, _Row, _Col, []).
calculateSum([M|Rest],List,Row,Col,[Y|Tail]):-
Col == Row -> Col1 is Col + 1,calculateSum(List,List,Row1,Col1,Tail);
calcHeu(Rest,L),
sum(L,S),
index(List, Row, Col, V),
Y is V + S,
%Row1 is Row + 1,
Col1 is Col + 1,
calculateSum(List,List,Row1,Col1,Tail).
为什么这个 Col == Row if 语句不起作用。有没有其他方法可以让如果 Row == Col 跳过该步骤?
编辑
通过做这样的事情。
(Col \= Row ->
calcHeu(Rest,L),
sum(L,S),
index(List, Row, Col, V),
Y is V + S,
Col1 is Col + 1,
calculateSum(List,List,Row1,Col1,Tail)
;
Col1 is Col + 1,calculateSum(List,List,Row1,Col1,Tail)
).
它无限地打印出 [22, , ,_......