You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "mg (JIRA)" <ji...@apache.org> on 2017/08/27 14:47:00 UTC

[jira] [Created] (GROOVY-8302) break/return/continue support in "Appended Block Closures"

mg created GROOVY-8302:
--------------------------

             Summary: break/return/continue support in "Appended Block Closures"
                 Key: GROOVY-8302
                 URL: https://issues.apache.org/jira/browse/GROOVY-8302
             Project: Groovy
          Issue Type: Proposal
          Components: Compiler
            Reporter: mg


This proposal revisits the idea to change the semantics of the break, return, and continue keyword for closures that are used in a way that mimics classical Java block constructs such as if, for, or while.

Example 1:
{code}
// Iterate over all PERSON rows in the result set
sqe.forEachRow("select * from PERSON") { final row ->
  if(row.TAG == 0) { break } // Leave forEachRow loop
  if(row.TAG == 1) { return } // return from the method enclosing the forEachRow loop
  if(row.TAG == 2) { continue } // Move to next iteration in the forEachRow loop
}
{code}


Example 2:
{code}
// Encapsulate with statically imported helper method that catches exceptions and ignores them, if the passed parameter is true
execWithOptionalIgnoreErrors(ignoreErrorsQ) {
  final x = dangerousOperation() 
  if(x == 1) { return } // return from the enclosing method
  // Note: break & continue are not allowed here
}
{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)