# Do ... while ... throws 'Unexpected token '{' when line break inside

**URL:** <https://discourse.processing.org/t/do-while-throws-unexpected-token-when-line-break-inside/22352>\
**Category:** Beginners\
**Created:** [July 3, 2020, 10:42am UTC](https://discourse.processing.org/t/do-while-throws-unexpected-token-when-line-break-inside/22352 "2020-07-03T10:42:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Laurent](https://discourse.processing.org/u/Laurent)\
**Post date:** [July 3, 2020, 10:42am UTC](https://discourse.processing.org/t/do-while-throws-unexpected-token-when-line-break-inside/22352/1 "2020-07-03T10:42:32Z")

</div>

Hi everyone,

Maybe I’m very tired and have a a dummy question but I’m in trouble with a simple do … while … statement… The following one:

```auto
  var number;

  do{
    
    number = random(1, 101);
    print(number);
    
  } while (number < 80);

```

throws the following exception message: Uncaught SyntaxError: Unexpected token ‘{’

I’ve searched for a long time before to find a solution. But I don’t understand it. If we delete the line breaks after and before the brackets, the problem is solved…

```auto
  do{
    number = random(1, 101);
    print(number);  
  } while (number < 80);

```

Any idea what is the reason of this rigidity? What do I wrong when inserting line breaks inside the do statement?

Thanks a lot for your insights!

Laurent

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [July 3, 2020, 10:54am UTC](https://discourse.processing.org/t/do-while-throws-unexpected-token-when-line-break-inside/22352/2 "2020-07-03T10:54:50Z")

</div>

Did you copy and paste the code from somewhere else e.g. a web page?

There are several ways to code _line breaks_ and _carriage returns_ and some are not compatible with Javascript. Unfortunately they are all non-printable character sequences so you can’t see the difference

---

<div class="post-metadata">

**Author:** ![Laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Laurent](https://discourse.processing.org/u/Laurent)\
**Post date:** [July 3, 2020, 11:15am UTC](https://discourse.processing.org/t/do-while-throws-unexpected-token-when-line-break-inside/22352/3 "2020-07-03T11:15:53Z")

</div>

Thanks @quark for your quick answer and relevant insight. Yes, it could be a good explanation, but unfortunately I didn’t copy/paste this code from another source or editor. I wrote it from the scratch into a new sketch in [editor.p5js.org](http://editor.p5js.org). Following your idea, the problem should be solved with deleting the space inside the editor and inserting new ones. But this doesn’t change anything (I’ve tried it many times without success…). Could it be an [editor.p5js.org](http://editor.p5js.org) bug?

---

<div class="post-metadata">

**Author:** ![Laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Laurent](https://discourse.processing.org/u/Laurent)\
**Post date:** [July 3, 2020, 2:11pm UTC](https://discourse.processing.org/t/do-while-throws-unexpected-token-when-line-break-inside/22352/4 "2020-07-03T14:11:59Z")

</div>

've tried once again replacing those line breaks and now it works. Maybe I did unconsciously a small copy/paste. Thanks again @quark

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [July 3, 2020, 2:34pm UTC](https://discourse.processing.org/t/do-while-throws-unexpected-token-when-line-break-inside/22352/5 "2020-07-03T14:34:03Z")

</div>

It has happened to me in the past when copying and pasting. Sometimes you et some weird character which makes it obvious but most of the time you see nothing and end up scratching your head. 😀
