How to loop function when contact in Box2d

I am trying to create a program so that the robots and the box will attract to each other when they are in contact (figure below)

I want them to keep being attracted when they are in contact
But my problem now is the code in beginContact() just ran once when they are in contact (code attached below)

May I know how can I solve this?


void beginContact(Contact cp) {

    //…code to get fixtures, body, and object…

    if (o1 == null || o2 == null)

    //collision of robot and box
    if (o1.getClass() == Box.class) { //o1 is box
      if (o2.getClass() == Robot.class) { //o2 is robot
        Robot r = (Robot) o2;

// I want these 3 rows to keep running as long as there’s contact made
        Vec2 force = box.attract(r);
        box.applyForce(force);	//applying force to box
        r.applyForce(force.mul(-1));	//applying force to robot(resultant force)