It activates Triangle()
with a parameter of 1.
Finally we are at the base case.
When Triangle()
is activated with a parameter of 1,
the if
statement causes the
value 1
to be immediately returned.
The chain of activations is called an activation chain. The picture shows the activation chain when it has reached the base case. The base case immediately returns a one.
public int Triangle( int N ) { if ( N == 1 ) return 1; else return N + Triangle( N-1 ); }
Look at the activation where N = 2
.
The if-statement has selected the false-branch and Triangle(1)
has just returned the value of one:
What value does this activation return to its caller?