# Can you attach the initialize variable block to your code?

**URL:** <https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195>\
**Category:** Questions about Thunkable X\
**Tags:** variables, help\
**Created:** [July 8, 2020, 3:37pm UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195 "2020-07-08T15:37:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rockode](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/rockode/32/75168_2.png) [@rockode](https://community.thunkable.com/u/rockode)\
**Post date:** [July 8, 2020, 3:37pm UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/1 "2020-07-08T15:37:09Z")

</div>

I need to initialize a variable in the code. I need to attach it to a if loop. This if loop is to happen as many times as the user wants it to. And everytime the user logs in, the if loop is performed. The values that the user enters has to be shown later. If I store those “infinite” no. of values in one variable, i dont think it would work. Please help.

---

<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:** [July 8, 2020, 4:17pm UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/2 "2020-07-08T16:17:42Z")

</div>

Can you use the Set variable block instead of the initialize block within your loop?

---

<div class="post-metadata">

**Author:** ![rockode](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/rockode/32/75168_2.png) [@rockode](https://community.thunkable.com/u/rockode)\
**Post date:** [July 8, 2020, 4:20pm UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/3 "2020-07-08T16:20:12Z")

</div>

No. I need to CREATE a new variable and this CREATING things will happen multiple times…

---

<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:** [July 13, 2020, 3:26am UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/4 "2020-07-13T03:26:30Z")

</div>

It sounds like you need to use a database instead of individual variables. You should use a data structure (such as AirTable or Google Sheets) that allows you to add and remove rows whenever you need to.

---

<div class="post-metadata">

**Author:** ![keerthideenudu](https://avatars.discourse-cdn.com/v4/letter/k/e68b1a/32.png) [@keerthideenudu](https://community.thunkable.com/u/keerthideenudu)\
**Post date:** [December 29, 2020, 10:39am UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/5 "2020-12-29T10:39:54Z")

</div>

how do i do this

---

<div class="post-metadata">

**Author:** ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)\
**Post date:** [December 29, 2020, 11:00am UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/6 "2020-12-29T11:00:16Z")

</div>

@keerthideenudu,

As @tatiang indicates you will probably need to use a database later on. But for now…

What you are describing is a list (aka Array). Thunkable variables have 4 different “scopes”

1. Cloud: shared by all users of your app
2. Stored: Saved on device until the app is uninstalled or the app Cached data is cleared
3. App: Only lasts until the app is closed
4. Screen: Only existing on a particular screen

From your description, it sounds like you want a Stored variable. Here is an example of how to initilize a Stored variable, then add a new entry each time the user opens the app.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/3/a33c58c79d36ad94a1bfb8af5153cf04d1216df1.png)

Happy Thunking!

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [December 29, 2020, 1:19pm UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/7 "2020-12-29T13:19:03Z")

</div>

> [@drted](#):
>
> Screen: Only existing on a particular screen

I have not seen this variable. I’ve only known of cloud, stored, and app variables but never encountered screen variables. How do I initialize one?

---

<div class="post-metadata">

**Author:** ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)\
**Post date:** [December 29, 2020, 1:58pm UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/8 "2020-12-29T13:58:26Z")

</div>

@codeswept,

These are created when you add a loop block.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [December 29, 2020, 2:12pm UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/9 "2020-12-29T14:12:58Z")

</div>

Oh, like j and i

---

<div class="post-metadata">

**Author:** ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)\
**Post date:** [December 29, 2020, 2:15pm UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/10 "2020-12-29T14:15:40Z")

</div>

Yes, but you can rename them to useful variables.

Function parameters also are screen level variables

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [December 30, 2020, 3:29am UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/11 "2020-12-30T03:29:57Z")

</div>

OK, thanks very much!

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 11:24am UTC](https://community.thunkable.com/t/can-you-attach-the-initialize-variable-block-to-your-code/665195/12 "2024-11-08T11:24:58Z")

</div>


