java - Continue keyword in recursion -



java - Continue keyword in recursion -

i have come across below code while searching answers.

public static void recurse(scanner in, hashmap<string, integer> oldmap) { hashmap<string, integer> map = null; if (oldmap == null) map = new hashmap<string, integer>(); else map = new hashmap<string, integer>(oldmap); while (in.hasnext) { string s = in.nextline(); if (s.startswith("[")) { recurse(in, map); continue; } if (s.startswith("]")) { break; } string[] split = s.split(" "); if (s.startswith("print")) { system.out.println(map.containskey(split[1]) ? map.get(split[1]) : 0); continue; } int x = 0; seek { x = integer.parse(split[1]); } grab (exception e) { x = map.containskey(split[1]) ? map.get(split[1]) : 0; } map.put(split[0], x); } }

can please explain me , why person has used go on after recursive call. seems go on not processed because each time recursion phone call processed.

it's true recursive phone call processed — then, eventually, recursive phone call return. (unless either raises exception or enters infinite loop, is.) after recursive phone call returns, continue statement executed.

it might help play simpler illustration of recursion:

public void printoneton(int n) { if(n > 1) { printoneton(n - 1); } system.out.println(n); }

as can see running (say) printoneton(10), after each recursive call, command returns caller. recursive phone call not replace caller.

java recursion

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -