Code Design 1 : works perfectly
public static void main (String[] args)
{
recursion(2);
}
public static void recursion(int num)
{
if (num > 0)
{
recursion( num - 1 );
System.out.println(num);
}
}
Code Design 2 : Infinite Loop. ?
public static void main (String[] args)
{
recursion(2);
}
public static void recursion(int num)
{
if (num == 0) return;
while (num > 0)
{
recursion( num - 1 );
System.out.println(num);
}
}
- Can someone plz help me in understanding why 2nd design is getting into infinite loop?
- I have already put return in 2nd design . So it should have worked fine. Also can you plz give me explanation in detail?