What happens to the counterclaim when complaint is dismissed?

The case may be dismissed, with a counterclaim set up under any of the following circumstances:
  1. Dismissal under Sec. 6, Rule 16 – where the defendant does not file motion to dismiss but raises the ground as an affirmative defense;
  2. Dismissal under Sec. 2, Rule 17 – where the plaintiff files a motion to dismiss the case, after the defendant had filed a responsive pleading; or
  3. Dismissal under Sec. 3, Rule 17 – where the complaint is dismissed due to the fault of the plaintiff. (All citations refer to those before the 2019 amendments.)
In all these cases, the rules expressly provide that the dismissal shall be without prejudice to the right of the defendant to pursue his counterclaim in the same or in a separate action.