我需要somenthing這樣的:如何在PROLOG中執行序列「If,Else If and Else」?
if(list.contains(var)){
//do something
}else if(list.contains(anotherVar1)){
//do something
}else if(list.contains(anotherVar2)){
//do something
}else if(list.contains(anotherVar3)){
//do something
}else{
// do something
}
編輯:
抱歉,我犯了一個錯誤。我需要這樣的:
if(list1.contains(var)){
//do something
}else if(list2.contains(var)){
//do something
}else if(list3.contains(var)){
//do something
}else if(list4.contains(var)){
//do something
}else{
// do something
}
我想這一點,但else
從未發生過:
((member(C,L1)-> print('first'));
(member(C,L2)-> print('second'));
(member(C,L3)-> print('third'));
(member(C,L4)-> print('fourth')));
(print('else')).
C是一種元素,我檢查,如果它是任何名單中的成員
我定義'測試(C,L1,L2,L3,L4)'你定義和'test(1,[],[],[],[])'打印'else' – coredump