0

I use drools to do some logic, the DRL is like that. My question is like that when I add "rules:Rules()", the loop will loop in "young" first until age larger than 19, but if I remove "rules:Rules()", it will only do once in young. Can someone tell me why?

rule "young"
when
   rules:Rules() 
   person:Person(Person.age< 19) 
then
    person.age+=1
    System.out.println("young"); 
end

rule "adult"
when
   rules:Rules() 
   person:Person(Person.age>= 19) 
then
    person.age+=1
    System.out.println("adult"); 
end
whathaha
  • 51
  • 1
  • 4
  • How many `Rules` do you have in your session? Is that the real RHS of your rules? I don't see how they could cause a loop given that you are not using `modify` nor `update` – Esteban Aliverti Dec 05 '18 at 08:15

1 Answers1

0

You should use modify to let Drools know you are changing the state of the person.

rule "young-without-rules"
when
   $person: Person(age < 19) 
then
    modify ($person) {
       age = age+1
    }
    System.out.println("young"); 
end
Master Drools
  • 728
  • 6
  • 18