MCPcopy Index your code
hub / github.com/beanshell/beanshell / BSHWhileStatement

Class BSHWhileStatement

src/bsh/BSHWhileStatement.java:31–87  ·  view source on GitHub ↗

This class handles both while statements and do..while statements.

Source from the content-addressed store, hash-verified

29 * This class handles both {@code while} statements and {@code do..while} statements.
30*/
31class BSHWhileStatement extends SimpleNode implements ParserConstants {
32
33 /**
34 * Set by Parser, default {@code false}
35 */
36 boolean isDoStatement;
37
38 BSHWhileStatement(int id) {
39 super(id);
40 }
41
42
43 public Object eval( CallStack callstack, Interpreter interpreter) throws EvalError {
44 int numChild = jjtGetNumChildren();
45
46 // Order of body and condition is swapped for do / while
47 final SimpleNode condExp;
48 final SimpleNode body;
49
50 if ( isDoStatement ) {
51 condExp = (SimpleNode) jjtGetChild(1);
52 body = (SimpleNode) jjtGetChild(0);
53 } else {
54 condExp = (SimpleNode) jjtGetChild(0);
55 if ( numChild > 1 ) {
56 body = (SimpleNode) jjtGetChild(1);
57 } else {
58 body = null;
59 }
60 }
61
62 boolean doOnceFlag = isDoStatement;
63
64 while (doOnceFlag || BSHIfStatement.evaluateCondition(condExp, callstack, interpreter)) {
65 doOnceFlag = false;
66 // no body?
67 if ( body == null ) {
68 continue;
69 }
70 Object ret = body.eval(callstack, interpreter);
71 if (ret instanceof ReturnControl) {
72 switch(( (ReturnControl)ret).kind ) {
73 case RETURN:
74 return ret;
75
76 case CONTINUE:
77 break;
78
79 case BREAK:
80 return Primitive.VOID;
81 }
82 }
83 }
84 return Primitive.VOID;
85 }
86
87}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected