2

I am learning stack and hearing this word called "Subroutine" too much. I am confused: what are exactly "routine" and "subroutine" ?

Let's suppose I have a program :

def tav(x):
    if x==0:
       return 19
    else:
       u=1
       tav(x-1)
       u+=1
tav(4)

So what are routine and subroutine in this program? I have read somewhere subroutine doesn't return anything so if I am getting right the inner portion of main function called subroutine or we can say directly subroutine is subprogram so in the above program subroutine should be:

if x==0:
    return 19
else:
    u=1
    tav(x-1)
    u+=1

Am I getting it right?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

1 Answers1

3

Routines and subroutines are the same. In older languages such as Fortran you had to differenciate between subroutines and functions. The latter returned something the former changed some state.

Niclas M
  • 192
  • 2
  • 9