All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax0.jamal.prog.commands.While Maven / Gradle / Ivy

There is a newer version: 2.8.1
Show newest version
package javax0.jamal.prog.commands;

import javax0.jamal.api.BadSyntax;

public class While implements Command {
    private final Expression condition;
    private final Block block;

    public While(final Expression condition, final Block block) {
        this.condition = condition;
        this.block = block;
    }


    @Override
    public String execute(final Context ctx) throws BadSyntax {
        ctx.step();
        final var sb = new StringBuilder();
        while (Operation.isTrue(condition.execute(ctx))) {
            sb.append(block.execute(ctx));
        }
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy