01: /*
02: * WhileCmd.java
03: *
04: * Copyright (c) 1997 Cornell University.
05: * Copyright (c) 1997 Sun Microsystems, Inc.
06: *
07: * See the file "license.terms" for information on usage and
08: * redistribution of this file, and for a DISCLAIMER OF ALL
09: * WARRANTIES.
10: *
11: * RCS: @(#) $Id: WhileCmd.java,v 1.1.1.1 1998/10/14 21:09:20 cvsadmin Exp $
12: *
13: */
14:
15: package tcl.lang;
16:
17: /**
18: * This class implements the built-in "while" command in Tcl.
19: */
20:
21: class WhileCmd implements Command {
22: /**
23: * This procedure is invoked to process the "while" Tcl command.
24: * See the user documentation for details on what it does.
25: *
26: * @param interp the current interpreter.
27: * @param argv command arguments.
28: * @exception TclException if script causes error.
29: */
30:
31: public void cmdProc(Interp interp, TclObject argv[])
32: throws TclException {
33: if (argv.length != 3) {
34: throw new TclNumArgsException(interp, 1, argv,
35: "test command");
36: }
37: String test = argv[1].toString();
38: TclObject command = argv[2];
39:
40: loop: {
41: while (interp.expr.evalBoolean(interp, test)) {
42: try {
43: interp.eval(command, 0);
44: } catch (TclException e) {
45: switch (e.getCompletionCode()) {
46: case TCL.BREAK:
47: break loop;
48:
49: case TCL.CONTINUE:
50: continue;
51:
52: case TCL.ERROR:
53: interp
54: .addErrorInfo("\n (\"while\" body line "
55: + interp.errorLine + ")");
56: throw e;
57:
58: default:
59: throw e;
60: }
61: }
62: }
63: }
64:
65: interp.resetResult();
66: }
67: }
|