[SOLVED] Call a function in it self?


I saw an example online that looks like this:

 def DecimalToBinary(num):

      if num >= 1:
         DecimalToBinary(num // 2)
      print(num % 2, end = '')


I’ll be happy if someone explain it to me.


This is called recursion. There is no problem as long as there is a break condition, in other words the calls to itself stop at some point. Otherwise you have an infinite loop.

Answered By – Philip Z.

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *