private void generateForeachArray(ForeachStatement node) {
            Expression range = node.getRange();
            Statement init = node.getInitializer();
            Statement body = node.getBody();

            // Holds the loop index value.
            final LocalVariable indexLocal =
                mBuilder.createLocalVariable(null, TypeDesc.INT);

            TypeDesc rangeDesc = makeDesc(range.getType(), false);
            // Holds the array to extract from.
            final LocalVariable rangeLocal =
                mBuilder.createLocalVariable(null, rangeDesc);
            generate(range);
            mBuilder.storeLocal(rangeLocal);

            // Generate init right after the range is evaluated.
            if (init != null) {
                generate(init);
            }

            Label endLabel = mBuilder.createLabel();

            if (range.getType().isNullable()) {
                // If range is null, just skip past the loop, avoiding a
                // NullPointerException.
                mBuilder.loadLocal(rangeLocal);
                mBuilder.ifNullBranch(endLabel, true);
            }

            mBuilder.loadLocal(rangeLocal);

            // Put the end index value onto the stack.
            mBuilder.arrayLength();

            // Holds the value to compare against for when the index has
            // reached the end and looping should stop.
            LocalVariable endIndexLocal = null;

            if (!node.isReverse()) {
                endIndexLocal =
                    mBuilder.createLocalVariable(null, TypeDesc.INT);
                mBuilder.storeLocal(endIndexLocal);
                mBuilder.loadConstant(0);
                mBuilder.storeLocal(indexLocal);
            }
            else {
                // endIndexLocal is not needed because its value is zero.
                mBuilder.storeLocal(indexLocal);
            }

            Label checkLabel = mBuilder.createLabel();
            mBuilder.branch(checkLabel);

            // Loop body begins here.
            Label startLabel = mBuilder.createLabel().setLocation();
            Label continueLabel = mBuilder.createLabel();
            saveContinueLabel(continueLabel);


            // Feed the loop variable with a value.
            final VariableRef loopVarRef = node.getLoopVariable();
            final Class<?> loopVarClass = loopVarRef.getType().getNaturalClass();
            final Class<?> rangeComponentClass = range.getType().getObjectClass().getComponentType();

            storeToVariable(loopVarRef.getVariable(), new Runnable() {
                public void run() {
                    mBuilder.loadLocal(rangeLocal);
                    mBuilder.loadLocal(indexLocal);
                    mBuilder.loadFromArray(makeDesc(loopVarRef.getType()));
                    if (loopVarClass != rangeComponentClass)
                        mBuilder.checkCast(makeDesc(loopVarRef.getType()));
                }
            });

            if (body != null) {
                generate(body);
            }

            // set entry point for continue
            continueLabel.setLocation();

            if (!node.isReverse()) {
                // Build check label location and index adjustment
                mBuilder.integerIncrement(indexLocal, 1);
                checkLabel.setLocation();

                mBuilder.loadLocal(indexLocal);

                mBuilder.loadLocal(endIndexLocal);
                mBuilder.ifComparisonBranch(startLabel, "<");
            }
            else {
                // Build check label location and index adjustment
                checkLabel.setLocation();
                mBuilder.integerIncrement(indexLocal, -1);

                mBuilder.loadLocal(indexLocal);

                mBuilder.ifZeroComparisonBranch(startLabel, ">=");
            }

            endLabel.setLocation();
        }