1 This file is break.def, from which is created break.c.
2 It implements the builtins "break" and "continue" in Bash.
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 1, or (at your option) any later
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING. If not, write to the Free Software
20 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 $FUNCTION break_builtin
27 Exit from within a FOR, WHILE or UNTIL loop. If N is specified,
32 #if defined (HAVE_UNISTD_H)
39 extern char *this_command_name;
41 static int check_loop_level ();
43 /* The depth of while's and until's. */
46 /* Non-zero when a "break" instruction is encountered. */
49 /* Non-zero when we have encountered a continue instruction. */
52 /* Set up to break x levels, where x defaults to 1, but can be specified
53 as the first argument. */
60 if (!check_loop_level ())
61 return (EXECUTION_FAILURE);
63 newbreak = get_numeric_arg (list);
66 return (EXECUTION_FAILURE);
68 if (newbreak > loop_level)
69 newbreak = loop_level;
73 return (EXECUTION_SUCCESS);
77 $FUNCTION continue_builtin
78 $SHORT_DOC continue [n]
79 Resume the next iteration of the enclosing FOR, WHILE or UNTIL loop.
80 If N is specified, resume at the N-th enclosing loop.
83 /* Set up to continue x levels, where x defaults to 1, but can be specified
84 as the first argument. */
86 continue_builtin (list)
91 if (!check_loop_level ())
92 return (EXECUTION_FAILURE);
94 newcont = get_numeric_arg (list);
97 return (EXECUTION_FAILURE);
99 if (newcont > loop_level)
100 newcont = loop_level;
102 continuing = newcont;
104 return (EXECUTION_SUCCESS);
107 /* Return non-zero if a break or continue command would be okay.
108 Print an error message if break or continue is meaningless here. */
112 #if defined (BREAK_COMPLAINS)
114 builtin_error ("only meaningful in a `for', `while', or `until' loop");
115 #endif /* BREAK_COMPLAINS */