public static void testTagbody() { var ref = new Object() { boolean continueRunning = true; }; Tag tag1 = tag(), tag2 = tag(); TagbodyElement code1 = () -> { if (ref.continueRunning) { ref.continueRunning = false; go(tag1); } else { go(tag2); } }; tagbody(() -> System.out.println("Hello world!"), tag1, () -> System.out.println("This should get printed twice"), code1, () -> System.out.println("This will not get printed"), tag2, () -> System.out.println("Goodbye world!")); } /* Hello world! This should get printed twice This should get printed twice Goodbye world! */