# Problems with print() function

**URL:** <https://discourse.processing.org/t/problems-with-print-function/27824>\
**Category:** Beginners\
**Created:** [February 14, 2021, 7:54pm UTC](https://discourse.processing.org/t/problems-with-print-function/27824 "2021-02-14T19:54:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirin](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@sirin](https://discourse.processing.org/u/sirin)\
**Post date:** [February 14, 2021, 7:54pm UTC](https://discourse.processing.org/t/problems-with-print-function/27824/1 "2021-02-14T19:54:20Z")

</div>

I am new to p5.js and I encountered a problem with a simple code:

```auto
var a=10;
var b;
function setup() {
  createCanvas(400, 400);
  //some expressions using variables go here
  
}
function draw() {
  background(220);
  //more expressions using variables go here
  print()
  }

```

If I add a print() function, before I am able to type in any parameters printer dialog  
opens and goes into an infinite loop. No matter I press **print** or **cancel** buttons, the dialog comes back.It does not happen all the time. Please advise!

---

<div class="post-metadata">

**Author:** ![WeinSim](https://avatars.discourse-cdn.com/v4/letter/w/db5fbb/32.png) [@WeinSim](https://discourse.processing.org/u/WeinSim)\
**Post date:** [February 14, 2021, 8:31pm UTC](https://discourse.processing.org/t/problems-with-print-function/27824/2 "2021-02-14T20:31:52Z")

</div>

I think in p5.js you use `console.log()` to print statements to the console

---

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [February 14, 2021, 8:42pm UTC](https://discourse.processing.org/t/problems-with-print-function/27824/3 "2021-02-14T20:42:53Z")

</div>

Hi @sirin, and welcome to the Processing Forum!

By default, the `draw()` function is called repeatedly. Therefore your call to `print()` occurs within an infinite loop. Add a call to `noLoop()` within the `setup()` function to prevent this, as follows:

```auto
function setup() {
  createCanvas(400, 400);
  //some expressions using variables go here
  noLoop();
}

```

---

<div class="post-metadata">

**Author:** ![sirin](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@sirin](https://discourse.processing.org/u/sirin)\
**Post date:** [February 14, 2021, 8:46pm UTC](https://discourse.processing.org/t/problems-with-print-function/27824/4 "2021-02-14T20:46:58Z")

</div>

Thank you, I am aware of that, but according to p5.js reference [reference | p5.js](https://p5js.org/reference/#/p5/print), print() also supposed to work. And it works, but not all the times. Is it a bug?

---

<div class="post-metadata">

**Author:** ![sirin](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@sirin](https://discourse.processing.org/u/sirin)\
**Post date:** [February 14, 2021, 8:52pm UTC](https://discourse.processing.org/t/problems-with-print-function/27824/5 "2021-02-14T20:52:42Z")

</div>

Thank you for your comment. The problem is not in print () peritedly working in draw().  
The problem is that print() with no arguments specified opens a dialog with my printer before I can add arguments to print().

---

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [February 14, 2021, 9:03pm UTC](https://discourse.processing.org/t/problems-with-print-function/27824/6 "2021-02-14T21:03:25Z")

</div>

After having stopped all instances of my copy of your program from running in the browser, I was able to add an argument to `print()`, as follows:

```auto
var a=10;
var b;
function setup() {
  createCanvas(400, 400);
  //some expressions using variables go here
  noLoop();
}
function draw() {
  background(220);
  //more expressions using variables go here
  print("Hello, World!");
}

```

The following was displayed in the JavaScript console when the program was started again:

```
Hello, World!
```

---

<div class="post-metadata">

**Author:** ![Pr0tonX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pr0tonx/32/2590_2.png) [@Pr0tonX](https://discourse.processing.org/u/Pr0tonX)\
**Post date:** [February 14, 2021, 11:33pm UTC](https://discourse.processing.org/t/problems-with-print-function/27824/7 "2021-02-14T23:33:27Z")

</div>

Hey @sirin , I suppose you’re using the p5 web editor with `auto refresh` enabled. As you mentionned, print aims to open a print dialog if you don’t pass a string or a variable in parameters. So, you can disabled the auto-refresh option while you type your code, give a string in your `print()` and then enable it again.  
Not convenient, I have to admit it.

---

<div class="post-metadata">

**Author:** ![sirin](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@sirin](https://discourse.processing.org/u/sirin)\
**Post date:** [February 15, 2021, 1:50am UTC](https://discourse.processing.org/t/problems-with-print-function/27824/8 "2021-02-15T01:50:53Z")

</div>

@Pr0tonX, thank you, this is the best advice I got as of now.
