# How to calculate a factorial of a number in thunkable using a loop?

**URL:** <https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442>\
**Category:** Questions about Thunkable X\
**Tags:** beginner, help\
**Created:** [June 13, 2023, 3:59am UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442 "2023-06-13T03:59:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![asserayman282w](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@asserayman282w](https://community.thunkable.com/u/asserayman282w)\
**Post date:** [June 13, 2023, 3:59am UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/1 "2023-06-13T03:59:16Z")

</div>

I have tried for days to make a loop in thunkable to get the factorial of a number, I want help, I am a beginner in thunkable, and this screen (that calculates the factorial) is a part of my first real project (a simple calculator)

 ![Screenshot 2023-06-13 142107](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/d/fd8943d6512c06339330e62b5cb317e593220e96.png)

My code

I am trying to make a variable that get the inputted number from the user, for example: If the user entered the number “5”, so, I am trying to make a loop that subtract 1 integer from that number, so the result will be “4”, then subtract 1 integer from “4”, so the result will be 3, and repeat this till it reach 1, then multiply all these values by the inputted number from user “5”

_ **The link to algorithm:** _ [Thunkable](https://x.thunkable.com/projects/646bca54fa089d672a5903de/fdc9e235-2d31-418f-8733-ad1a0a071814/blocks)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 13, 2023, 4:26am UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/2 "2023-06-13T04:26:40Z")

</div>

When you post on the forums, you should choose a short title instead of including your entire question in the title. I’ve shortened the title for you.

Please provide a link to the algorithm that you’re using to create a factorial calculator. Because what you have doesn’t seem like it’s following a correct algorithm.

There are also several topics about factorials on the forums so you may want to search for those.

---

<div class="post-metadata">

**Author:** ![asserayman282w](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@asserayman282w](https://community.thunkable.com/u/asserayman282w)\
**Post date:** [June 13, 2023, 6:18pm UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/3 "2023-06-13T18:18:53Z")

</div>

I have tried for days to make a loop in thunkable to get the factorial of a number, I want help, I am a beginner in thunkable, and this screen (that calculates the factorial) is a part of my first real project (a simple calculator)

 ![Screenshot 2023-06-13 142107](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/d/fd8943d6512c06339330e62b5cb317e593220e96.png)  
My code

I am trying to make a variable that get the inputted number from the user, for example: If the user entered the number “5”, so, I am trying to make a loop that subtract 1 integer from that number, so the result will be “4”, then subtract 1 integer from “4”, so the result will be 3, and repeat this till it reach 1, then multiply all these values by the inputted number from user “5”

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 13, 2023, 9:26pm UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/4 "2023-06-13T21:26:31Z")

</div>

Please don’t start a second topic for the same issue. You can add more details to your original topic:

> [@How to calculate a factorial of a number in thunkable using a loop?](https://community.thunkable.com/t/how-to-calculate-a-factorial/2463442):
>
> I have tried for days to make a loop in thunkable to get the factorial of a number, I want help, I am a beginner in thunkable, and this screen (that calculates the factorial) is a part of my first real project (a simple calculator) My code I am trying to make a variable that get the inputted number from the user, for example: If the user entered the number “5”, so, I am trying to make a loop that subtract 1 integer from that number, so the result will be “4”, t…

In that topic, I asked for a link to an algorithm. Factorials have been studied for centuries so you shouldn’t have to invent a method for calculating them. If you provide a link, I’ll help you figure out the blocks for that algorithm.

The method you described above is actually much harder than the established recursive method.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 13, 2023, 9:40pm UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/5 "2023-06-13T21:40:10Z")

</div>

@matt can you merge this with the original topic (link above)? Thanks!

---

<div class="post-metadata">

**Author:** ![asserayman282w](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@asserayman282w](https://community.thunkable.com/u/asserayman282w)\
**Post date:** [June 14, 2023, 3:54am UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/6 "2023-06-14T03:54:08Z")

</div>

Sorry, it’s the first time for me asking a question on programming forums (like thunkable),  
I’ve updated the original topic  
and again I am very sorry for the confusion I did 🙂

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 14, 2023, 4:14am UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/7 "2023-06-14T04:14:06Z")

</div>

An [algorithm](https://www.programiz.com/dsa/algorithm) is a step-by-step guide to doing something with code.

What I’m suggesting is that you Google how to calculate factorials recursively. And then use the algorithm (the written steps) as a guide for setting up your blocks in Thunkable.

If you instead want to use your method, you would need to store the current _product_ in a variable so that you can multiply it by the current value in the loop (5, then 4, then 3, etc.).

---

<div class="post-metadata">

**Author:** ![asserayman282w](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@asserayman282w](https://community.thunkable.com/u/asserayman282w)\
**Post date:** [June 14, 2023, 4:23am UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/8 "2023-06-14T04:23:11Z")

</div>

Thanks sir 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [September 11, 2023, 6:19pm UTC](https://community.thunkable.com/t/how-to-calculate-a-factorial-of-a-number-in-thunkable-using-a-loop/2463442/9 "2023-09-11T18:19:34Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
