# What does the return 0 block does

**URL:** https://forum.makecode.com/t/what-does-the-return-0-block-does/3204
**Category:** Help
**Created:** [August 23, 2020, 1:08pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204 "2020-08-23T13:08:14Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 23, 2020, 1:08pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/1 "2020-08-23T13:08:14Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/1abd95db2ec836c198982a0fb1cee359af0babe3.png)

What does it do?

---

<div class="post-metadata">

### Author: ![MKleinSB](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mkleinsb/32/593_2.png) [@MKleinSB](https://forum.makecode.com/u/MKleinSB)
#### Post date: [August 23, 2020, 2:53pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/2 "2020-08-23T14:53:30Z")

</div>

It´s only for functions to return a value.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [August 23, 2020, 4:52pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/3 "2020-08-23T16:52:21Z")

</div>

It allows you to return a value from your functions.  
So if you were to write a function to get the distance between to sprites, you can return the distance instated of setting a global variable to the distance. It makes your code cleaner

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 23, 2020, 9:33pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/4 "2020-08-23T21:33:08Z")

</div>

Sorry. I don’t understand

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 23, 2020, 11:27pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/5 "2020-08-23T23:27:59Z")

</div>

What value do you return

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [August 24, 2020, 2:24am UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/6 "2020-08-24T02:24:00Z")

</div>

You can return any number you want.

---

<div class="post-metadata">

### Author: ![LcAtonal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/lcatonal/32/16800_2.png) [@LcAtonal](https://forum.makecode.com/u/LcAtonal)
#### Post date: [August 24, 2020, 6:33am UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/7 "2020-08-24T06:33:35Z")

</div>

Does it means call the function how many times??

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 24, 2020, 11:17am UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/8 "2020-08-24T11:17:58Z")

</div>

> [@LcAtonal](#):
>
> Does it means call the function how many times??

yeah is that what it means?

---

<div class="post-metadata">

### Author: ![MKleinSB](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mkleinsb/32/593_2.png) [@MKleinSB](https://forum.makecode.com/u/MKleinSB)
#### Post date: [August 24, 2020, 12:54pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/9 "2020-08-24T12:54:40Z")

</div>

No, you make a function like squareroot. If you call squareroot with the parameter 9 you will return 3.  
 ![grafik](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/b/b38c62a1f99330ad16a035f54b537f6482c63f07.png)

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [August 24, 2020, 2:06pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/10 "2020-08-24T14:06:25Z")

</div>

Functions are designed to wrap up everything needed to do a specific thing, such as spawning a enemy, or calculating the distance between 2 sprites.

You already know that you can pass parameters to functions, like the X and Y of where you want the sprite to spawn or the 2 sprites you want to get the distance from.

Now say you wrote a function to calculate the distance between 2 sprites. You can pass in the 2 sprites as parameters. If you use the return block, the function will exit and return the value you pass in. (The default is 0, as you can see) instead of setting a global variable to the result and reading it (which is very messy and not expandable), you can return it, like how you can pass in a number to the square root function and it returns the square root of the number you pass in.

You see how the square root function is a oval, not a block? That’s because it returns a value, and you can use that to set a variable, or pass it directly to another function!

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 24, 2020, 5:07pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/11 "2020-08-24T17:07:33Z")

</div>

I’m only in eighth grade. This is so hard to understand

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [August 24, 2020, 5:24pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/12 "2020-08-24T17:24:32Z")

</div>

I am too.

Don’t worry, you’ll get it 😉

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [August 24, 2020, 5:58pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/13 "2020-08-24T17:58:34Z")

</div>

Look at this project:

> **[Functions](https://arcade.makecode.com/22634-56251-62295-41706)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

  
Open the code.

Notice how there are 3 functions that preform the exact same thing. This is the Euclidean distance function. It’s used to calculate the distance between 2 points on a grid.

`calculate_distamce_1` is function that takes the `x` and `y` of the `Apple` and the `Burger` sprite, feeds the values into the formula, and assigns the result to the `Distance` variable. It’s very inflexible, because it can only calculate the distance between the `Apple` and the `Burger` sprite and has to use a global variable to pass the output to the caller, which could easily lead to bugs in your code.

`calculate_distance_2` is the exact same function as `calculate_distance_1`, except you can pass in the sprites you want to calculate the distance between them. This function is much more flexible than the last one because you can run this function with any 2 sprites, making the function more useful. But, it’s still using the same global variable `Distance` to pass the result back, which means you can’t use that variable again until you are done with it.

`calculate_distance_3` is the best function out of all of them. It has the ability to allow you to choose whichever sprites you want to calculate the distance between AND it uses the `return` block, so the function turns into an oval, which means it returns a value, It doesn’t need any global variables except the 2 sprites you are passing in.

Do you understand?

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 24, 2020, 7:19pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/14 "2020-08-24T19:19:58Z")

</div>

TIL  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/6/6c1d61d09abcf4767cc332f2c4484de3517e4b9a.png)  
The distance is  
the square root of (110-37 \*\* 2) + 75-15 = that really long decimal

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2a0236ecf536dbace168abfa12374d93c13bf23d.png)  
The second distance is equal to the first one.  
Distance is equal to the (square root 110-37 \*\* 2) + 75-15 \*\* 2 = other really long decimal I said before  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c6bd3bbbe7c0c0bcd4fa35b178f8c8833858d434.png)  
Then you return the value that you have and just use those numbers again I guess

I hope I said that correctly.  
Thx @UnsignedArduino  
Still a little bit confused so I hope I didn’t do all this for nothing

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [August 24, 2020, 8:15pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/15 "2020-08-24T20:15:13Z")

</div>

Umm…i don’t think that’s what I was intending to get across.

Here’s a part from `Programming Arduino - Getting Started with Sketches` by Simon Monk. Yes, it’s Arduino, but the explanation on functions is really good.

**What Is a Function?**  
A function is a little like a program within a program. You can use it to wrap up some little thing that you want to do. A function that you define can be called from anywhere in your sketch (In this case, your code, but I’m just directly quoting him) and contain its own variables and its own list of commands. When the commands have been run, execution returns to the point just after wherever it was in the code that called the function.  
…  
**Parameters**  
When dividing your sketch and up into functions it often were thinking about what service a function could provide in the case of **flash** (In our case, `calculate_distance_2`) this is fairly obvious but this time let’s give this function parameters to tell it both how many times to flash and how short or long the flashes should be. (In our case, the 2 sprites we are passing in)  
…  
**Return Values**  
Computer science, as an academic discipline, has its parents mathematics and engineering. This heritage lingers on in many of the names associated with programming. The word _function_ is itself a mathematical term. In mathematics the input to the function (the argument) completely determines the output. We have written functions that take an input, but none that give us back a value.  
…  
Let’s take a look at writing a function that takes a temperature in degrees Centigrade and returns the equivalent in degrees Fahrenheit:

```auto
// C++
int centToFaren(int c):
{
    int f = c * 9 / 5 + 32;
    return f;
}

```

```javascript
// Typescript
// I suck at TS so this might be wrong
function centToFaren(c: number) {
    let f: number = c * 9 / 5 + 32
    return f
}

```

```auto
# Python 3
def centToFaren(c: int):
    f = c * 9 / 5 + 32
    return f

```

Blocks:

 ![Screenshot_20200824-155433](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e78a6dcb104af4f20687a33fcca96e434bef18dc.jpeg)  
The function definition now starts with `int` rather than `void` to indicate that the function will return and `int` to whatever calls it. (In our case, the function is now an oval, rather than a block, to indicate that it returns something) This might be a bit of code that looks like this:

```auto
// C++
int pleasantTemp = centToFaren(20);

```

```javascript
// Typescript
// I suck at this so I might be wrong
let pleasantTemp: number = centToFaren(20)

```

```auto
# Python 3
pleasantTemp = centToFaren(20)

```

Blocks:

 ![Screenshot_20200824-160253](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/1472ec8ca547db8ada123a592520e6827b344388.jpeg)

Did I make it more confusing?

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 24, 2020, 8:22pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/16 "2020-08-24T20:22:43Z")

</div>

Kinda but not really. I know about functions but never knew what the text or boolean or sprite (or anything else in that area) when you make a function. I don’t know python or javascript or typescript. I’m into mainly blocks.

I’m gonna pretend that c=2  
f is equal to 55 then return f is return 55

And the A button turns on the function Call centToFaren

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 24, 2020, 8:23pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/17 "2020-08-24T20:23:44Z")

</div>

Wait a minute. you are changing farenheit to celcius

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [August 24, 2020, 8:24pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/18 "2020-08-24T20:24:49Z")

</div>

I defined a function in the post above to convert Centigrade to Fahrenheit. It makes use of the return statement in the return values section

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [August 24, 2020, 8:25pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/19 "2020-08-24T20:25:29Z")

</div>

uhmmmm  
Still confused but I know about temperature

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [August 24, 2020, 8:25pm UTC](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204/20 "2020-08-24T20:25:45Z")

</div>

I’m so sorry, I must be really confusing you.

[Next page](https://forum.makecode.com/t/what-does-the-return-0-block-does/3204.md?page=2)
