sagiv ben giat (2018-02-17T21:02:22.000Z)
I hope I'm on the right medium for this, I would like to propose a language
feature.
withBreak blocks

Well the name might not be the best, but it's just my way to be the most
clear about this feature proposal.

I often find my self doing this in my code:

const doWork = () => {
  // try catch omitted for brevity
  const response = fetchData();
  do {
    if (response.error) {
      log(response.message);
      break;
    }
    if (!response.data) {
      log("No data");
      break;
    }
    if (!response.data.todos) {
      log("No Todos");
      break;
    }
    return action({ data: response.data });
  } while (false);
};

I'm doing this instead of doing bunch of  if / else if / else blocks or
ugly nested if blocks.
 What i would like to have is a block that will let me break without being
in a loop context.
Something like this:
withBreak {
  if (response.error) {
    log(response.message);
    break;
  }
  if (!response.data) {
    log("No data");
    break;
  }
  if (!response.data.todos) {
    log("No Todos");
    break;
  }
  return action({ data: response.data });
}

This can be a synthetic sugar for do{}while(false)  behind the scenes.

Best regards,

Sagiv B.G
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180217/a904caa8/attachment.html>
sagiv.bengiat at gmail.com (2018-02-17T21:21:43.188Z)
I hope I'm on the right medium for this, I would like to propose a language
feature.
withBreak blocks

Well the name might not be the best, but it's just my way to be the most
clear about this feature proposal.

I often find my self doing this in my code:

```
const doWork = () => {
  // try catch omitted for brevity
  const response = fetchData();
  do {
    if (response.error) {
      log(response.message);
      break;
    }
    if (!response.data) {
      log("No data");
      break;
    }
    if (!response.data.todos) {
      log("No Todos");
      break;
    }
    return action({ data: response.data });
  } while (false);
};
```
I'm doing this instead of doing bunch of  if / else if / else blocks or
ugly nested if blocks.
 What i would like to have is a block that will let me break without being
in a loop context.
Something like this:
```
withBreak {
  if (response.error) {
    log(response.message);
    break;
  }
  if (!response.data) {
    log("No data");
    break;
  }
  if (!response.data.todos) {
    log("No Todos");
    break;
  }
  return action({ data: response.data });
}
```
This can be a synthetic sugar for do{}while(false)  behind the scenes.

Best ,

Sagiv B.G