vfmt on `break(2)` statement

Created on 11 Nov 2020  Â·  6Comments  Â·  Source: vlang/v

V version: V 0.1.29 2994e71
OS: macos, Mac OS X, 10.15.6, 19G2021

What did you do?

// source
if idx >= maxlen {
  break(2)
}

What did you expect to see?

No change

What did you see instead?

// vfmt output
if idx >= maxlen {
  break
  (2)
}

Possibly related? #6005

Bug

All 6 comments

This is correct behavior.

break doesn't have any arguments, and V doesn't use semicolons to separate statements, so (2) is parsed as the next statement.

Sorry – I just realized that this came from a C extension I've used in the past, and not C directly 🤦
Something like https://github.com/xbarin02/c-ext#some-examples

Is there a V shorthand for breaking a nested loop? In JS, this is something like:

outer: for (let i=0; i < foo.length; i++) {
  for (let j=0; j < bar.length; j++) {
    if (condition) break outer;
  }
}

Not yet, but it's planned.

Thank you; feel free to mark this as invalid.

This has just been implemented by @ntrel

@lukeed

Amazing, thank you @ntrel!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

radare picture radare  Â·  3Comments

elimisteve picture elimisteve  Â·  3Comments

lobotony picture lobotony  Â·  3Comments

PavelVozenilek picture PavelVozenilek  Â·  3Comments

shouji-kazuo picture shouji-kazuo  Â·  3Comments