include::../description.adoc[]

== Noncompliant Code Example

----
enum class OP{
    ADD
    /* ... */
};

class Stack{
    public:
    int pop();
    void push(int i);
    /* ... */
};

void evaluate(OP op, Stack& stack) {
  switch (op) {
    /* ... */
    case OP::ADD: { // Noncompliant - nested code block '{' ... '}'
      int a = stack.pop();
      int b = stack.pop();
      int result = a + b;
      stack.push(result);
      break;
    }
    /* ... */
  }
}
----

== Compliant Solution

----
enum class OP{
    ADD
    /* ... */
};

class Stack{
    public:
    int pop();
    void push(int i);
    /* ... */
};

static void evaluateAdd(Stack& stack) { 
  int a = stack.pop();
  int b = stack.pop();
  int result = a + b;
  stack.push(result); 
}

void evaluate(OP op, Stack& stack) {
  switch (op) {
    /* ... */
    case OP::ADD: // Compliant
      evaluateAdd(stack);
      break;
    /* ... */
  }
}
----

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
