Please cherish the work of small production. This article is the original small, reproduced please indicate the source.
There are times when we need to force a recursive leap in the middle. And still need a step out, and a layer of jumping out. At this point, we can use the method of throwing exceptions to achieve.
Class Test {Static Class Stopmsgexception extends RuntimeException { } public static void Main (String args[]) {
try { run (0); } catch (Stopmsgexception e) { System.out.println (e); } } public static void run (int t) { if (T >) { //jump out of throw new Stopmsgexception (); } Run Operation System.out.println (t); Recursive run (t + 1);} }
This small sample of the method to achieve this function
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Java forced out the middle of recursion