# About public voids / functions

**URL:** <https://discourse.processing.org/t/about-public-voids-functions/21469>\
**Category:** Beginners\
**Created:** [June 1, 2020, 7:42am UTC](https://discourse.processing.org/t/about-public-voids-functions/21469 "2020-06-01T07:42:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SouSageYa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sousageya/32/9819_2.png) [@SouSageYa](https://discourse.processing.org/u/SouSageYa)\
**Post date:** [June 1, 2020, 7:42am UTC](https://discourse.processing.org/t/about-public-voids-functions/21469/1 "2020-06-01T07:42:04Z")

</div>

Hi. Do I have to place Public Voids into void draw if I want to use it repeatedly ??

---

<div class="post-metadata">

**Author:** ![cansik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cansik/32/8815_2.png) [@cansik](https://discourse.processing.org/u/cansik)\
**Post date:** [June 1, 2020, 8:41am UTC](https://discourse.processing.org/t/about-public-voids-functions/21469/2 "2020-06-01T08:41:57Z")

</div>

To answer your question: No, it’s not allowed to defined a function inside another method in Processing.

Explanation: `public void` is just the header of a function you are defining. Usually followed by the name of the function and it’s parameters. In the curly brackets the content / body of your function is defined.

`public` means, that it is [visible](https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html) to anyone else. Usually you do not need that in your own sketches.

`void` means that this function is not returning anything. Return means, that a method calculates something (for example a math method `f(x) = x^2`). This function is taking in a number and returning one. In Processing it would look like this:

```auto
int f(x) {
  return pow(x, 2);
}

```

Now to call this method repeatedly inside your sketch, you can define in the global scope (outside of draw) and **call** it inside draw. Calling a method is done by writing its name and giving it it’s parameters:

```auto
void draw() {
  int result = f(2);
  println(result);
}

```

And just a side note, because it leads to a lot of confusion:  
The method `hello()` is not returning anything, even there is something written to the console. This method produces output, but no return values.

```auto
void hello() {
  println("test");
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 1, 2020, 9:19am UTC](https://discourse.processing.org/t/about-public-voids-functions/21469/3 "2020-06-01T09:19:08Z")

</div>

> [@SouSageYa](#):
>
> place Public Voids into void draw if I want to use it repeatedly ??

Please don’t say voids, say functions.

void is just the return type.

So, yeah, you define the function and then call it in draw().

see [programming and functions · Kango/Processing-snippets Wiki · GitHub](https://github.com/Kango/Processing-snippets/wiki/programming-and-functions)

```auto
void setup() {
  size(600, 500);
  noFill();
  stroke(255, 200, 120);
  strokeWeight(3);
}
        
void draw() {
  background(0);
  rightAngle(260, 180);
}
    
void rightAngle(float startX, float startY) {
  line (startX, startY, startX+100, startY);
  line (startX+100, startY, startX+100, startY+100);
}

```

---

<div class="post-metadata">

**Author:** ![SouSageYa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sousageya/32/9819_2.png) [@SouSageYa](https://discourse.processing.org/u/SouSageYa)\
**Post date:** [June 1, 2020, 10:08am UTC](https://discourse.processing.org/t/about-public-voids-functions/21469/4 "2020-06-01T10:08:48Z")

</div>

Thanks to both of you guys I appreciate it.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 1, 2020, 2:04pm UTC](https://discourse.processing.org/t/about-public-voids-functions/21469/5 "2020-06-01T14:04:34Z")

</div>

and of course you can (and must sometimes) call the same function multiple times from draw()

```auto
void setup() {
  size(600, 500);

  noFill();
  stroke(255, 200, 120);
  strokeWeight(3);
}

void draw() {
  background(0);

  rightAngle(260, 180);
  rightAngle(260-30, 180-30);
  rightAngle(260-30-30, 180-30-30);
}

void rightAngle(float startX, float startY) {
  line (startX, startY, startX+100, startY);
  line (startX+100, startY, startX+100, startY+100);
}

```
