user7026515
user7026515

Reputation:

What are routine and subroutine in program?

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?

Upvotes: 2

Views: 3268

Answers (1)

Niclas M
Niclas M

Reputation: 312

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.

Upvotes: 3

Related Questions