1 .\" $OpenBSD: bc,v 1.9 2004/07/09 10:23:05 jmc Exp $
2 .\" $DragonFly: src/usr.bin/bc/USD.doc/bc,v 1.1 2004/09/20 04:20:35 dillon Exp $
4 .\" Copyright (C) Caldera International Inc. 2001-2002.
5 .\" All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code and documentation must retain the above
11 .\" copyright notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed or owned by Caldera
18 .\" International, Inc.
19 .\" 4. Neither the name of Caldera International, Inc. nor the names of other
20 .\" contributors may be used to endorse or promote products derived from
21 .\" this software without specific prior written permission.
23 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
24 .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
25 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT,
28 .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33 .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 .\" POSSIBILITY OF SUCH DAMAGE.
36 .\" @(#)bc 6.2 (Berkeley) 4/17/91
42 .EH 'USD:6-%''BC \- An Arbitrary Precision Desk-Calculator Language'
43 .OH 'BC \- An Arbitrary Precision Desk-Calculator Language''USD:6-%'
46 BC \- An Arbitrary Precision Desk-Calculator Language
54 BC is a language and a compiler for doing arbitrary precision arithmetic
55 on the PDP-11 under the
58 system. The output of the compiler is interpreted and executed by
59 a collection of routines which can input, output, and do
60 arithmetic on indefinitely large integers and on scaled fixed-point
63 These routines are themselves based on a dynamic storage allocator.
64 Overflow does not occur until all available core storage
67 The language has a complete control structure as well as immediate-mode
68 operation. Functions can be defined and saved for later execution.
70 Two five hundred-digit numbers can be multiplied to give a
71 thousand digit result in about ten seconds.
73 A small collection of library functions is also available,
74 including sin, cos, arctan, log, exponential, and Bessel functions of
77 Some of the uses of this compiler are
79 to do computation with large integers,
81 to do computation accurate to many decimal places,
83 conversion of numbers from one base to another base.
89 BC is a language and a compiler for doing arbitrary precision
92 time-sharing system [1].
93 The compiler was written to make conveniently available a
94 collection of routines (called DC [5]) which are capable of doing
95 arithmetic on integers of arbitrary size. The compiler
96 is by no means intended to provide a complete programming
98 It is a minimal language facility.
100 There is a scaling provision that permits the
101 use of decimal point notation.
102 Provision is made for input and output in bases other than
103 decimal. Numbers can be converted from decimal to octal by
104 simply setting the output base to equal 8.
106 The actual limit on the number of digits that can
107 be handled depends on the amount of storage available on the machine.
108 Manipulation of numbers with many hundreds of digits
109 is possible even on the smallest versions of
112 The syntax of BC has been deliberately selected to agree
113 substantially with the C language [2]. Those who
114 are familiar with C will find few surprises in this language.
116 Simple Computations with Integers
118 The simplest kind of statement is an arithmetic expression
120 For instance, if you type in the line:
126 the program responds immediately with the line
132 The operators \-, *, /, %, and ^ can also be used; they
133 indicate subtraction, multiplication, division, remaindering, and
134 exponentiation, respectively. Division of integers produces an
135 integer result truncated toward zero.
136 Division by zero produces an error
139 Any term in an expression may be prefixed by a minus sign to
140 indicate that it is to be negated (the `unary' minus sign).
147 is interpreted to mean that \-3 is to be added to 7.
149 More complex expressions with several operators and with
150 parentheses are interpreted just as in
151 Fortran, with ^ having the greatest binding
152 power, then * and % and /, and finally + and \-.
153 Contents of parentheses are evaluated before material
154 outside the parentheses.
156 performed from right to left and the other operators
164 are equivalent, as are the two expressions
170 BC shares with Fortran and C the undesirable convention that
172 \fBa/b*c\fP is equivalent to \fB(a/b)*c\fP
176 Internal storage registers to hold numbers have single lower-case
177 letter names. The value of an expression can be assigned to
178 a register in the usual way. The statement
184 has the effect of increasing by three the value of the contents of the
186 When, as in this case, the outermost operator is an =, the
187 assignment is performed but the result is not printed.
188 Only 26 of these named storage registers are available.
190 There is a built-in square root function whose
191 result is truncated to an integer (but see scaling below).
199 produce the printed result
208 There are special internal quantities, called `ibase' and `obase'.
209 The contents of `ibase', initially set to 10,
210 determines the base used for interpreting numbers read in.
211 For example, the lines
218 will produce the output line
224 and you are all set up to do octal to decimal conversions.
225 Beware, however of trying to change the input base back
232 Because the number 10 is interpreted as octal, this statement will
234 For those who deal in hexadecimal notation,
235 the characters A\-F are permitted in numbers
236 (no matter what base is in effect)
238 interpreted as digits having values 10\-15 respectively.
245 will change you back to decimal input base no matter what the
246 current input base is.
247 Negative and large positive input bases are
248 permitted but useless.
249 No mechanism has been provided for the input of arbitrary
250 numbers in bases less than 1 and greater than 16.
252 The contents of `obase', initially set to 10, are used as the base for output
260 will produce the output line
266 which is to be interpreted as a 3-digit hexadecimal number.
267 Very large output bases are permitted, and they are sometimes useful.
268 For example, large numbers can be output in groups of five digits
269 by setting `obase' to 100000.
270 Strange (i.e. 1, 0, or negative) output bases are
271 handled appropriately.
273 Very large numbers are split across lines with 70 characters per line.
274 Lines which are continued end with \\.
275 Decimal output conversion is practically instantaneous, but output
276 of very large numbers (i.e., more than 100 digits) with other bases
278 Non-decimal output conversion of
279 a one hundred digit number takes about
282 It is best to remember that `ibase' and `obase' have no effect
283 whatever on the course of internal computation or
284 on the evaluation of expressions, but only affect input and
285 output conversion, respectively.
289 A third special internal quantity called `scale' is
290 used to determine the scale of calculated
293 up to a specific number of decimal digits after the decimal point.
294 This fractional part is retained in further computations.
295 We refer to the number of digits after the decimal point of
296 a number as its scale.
297 The current implementation allows scales to be as large as can be
298 represented by a 32-bit unsigned number minus one.
299 This is a non-portable extension.
300 The original implementation allowed for a maximum scale of 99.
302 When two scaled numbers are combined by
303 means of one of the arithmetic operations, the result
304 has a scale determined by the following rules. For
305 addition and subtraction, the scale of the result is the larger
306 of the scales of the two operands. In this case,
307 there is never any truncation of the result.
308 For multiplications, the scale of the result is never
309 less than the maximum of the two scales of the operands,
310 never more than the sum of the scales of the operands
311 and, subject to those two restrictions,
312 the scale of the result is set equal to the contents of the internal
314 The scale of a quotient is the contents of the internal
315 quantity `scale'. The scale of a remainder is
316 the sum of the scales of the quotient and the divisor.
317 The result of an exponentiation is scaled as if
318 the implied multiplications were performed.
319 An exponent must be an integer.
320 The scale of a square root is set to the maximum of the scale
321 of the argument and the contents of `scale'.
323 All of the internal operations are actually carried out in terms
324 of integers, with digits being discarded when necessary.
325 In every case where digits are discarded, truncation and
326 not rounding is performed.
329 `scale' must be no greater than
330 4294967294 and no less than 0. It is initially set to 0.
332 The internal quantities `scale', `ibase', and `obase' can be
333 used in expressions just like other variables.
340 increases the value of `scale' by one, and the line
346 causes the current value of `scale' to be printed.
348 The value of `scale' retains its meaning as a
349 number of decimal digits to be retained in internal
350 computation even when `ibase' or `obase' are not equal to 10.
351 The internal computations (which are still conducted in decimal,
352 regardless of the bases) are performed to the specified number
353 of decimal digits, never hexadecimal or octal or any
354 other kind of digits.
358 The name of a function is a single lower-case letter.
359 Function names are permitted to collide with simple
361 Twenty-six different defined functions are permitted
362 in addition to the twenty-six variable names.
369 begins the definition of a function with one argument.
370 This line must be followed by one or more statements,
371 which make up the body of the function, ending
372 with a right brace }.
373 Return of control from a function occurs when a return
374 statement is executed or when the end of the function is reached.
375 The return statement can take either
383 In the first case, the value of the function is 0, and in
384 the second, the value of the expression in parentheses.
386 Variables used in the function can be declared as automatic
387 by a statement of the form
393 There can be only one `auto' statement in a function and it must
394 be the first statement in the definition.
395 These automatic variables are allocated space and initialized
396 to zero on entry to the function and thrown away on return. The
397 values of any variables with the same names outside the function
399 Functions may be called recursively and the automatic variables
400 at each level of call are protected.
401 The parameters named in a function definition are treated in
402 the same way as the automatic variables of that function
403 with the single exception that they are given a value
404 on entry to the function.
405 An example of a function definition is
415 The value of this function, when called, will be the
419 A function is called by the appearance of its name
420 followed by a string of arguments enclosed in
421 parentheses and separated by commas.
423 is unpredictable if the wrong number of arguments is used.
425 Functions with no arguments are defined and called using
426 parentheses with nothing between them: b().
432 above has been defined, then the line
438 would cause the result 21.98 to be printed and the line
444 would cause the value of x to become 60.
446 Subscripted Variables
448 A single lower-case letter variable name
449 followed by an expression in brackets is called a subscripted
450 variable (an array element).
451 The variable name is called the array name and the expression
452 in brackets is called the subscript.
453 Only one-dimensional arrays are
454 permitted. The names of arrays are permitted to
455 collide with the names of simple variables and function names.
457 part of a subscript is discarded before use.
458 Subscripts must be greater than or equal to zero and
459 less than or equal to 2047.
461 Subscripted variables may be freely used in expressions, in
462 function calls, and in return statements.
464 An array name may be used as an argument to a function,
465 or may be declared as automatic in
466 a function definition by the use of empty brackets:
474 When an array name is so used, the whole contents of the array
475 are copied for the use of the function, and thrown away on exit
477 Array names which refer to whole arrays cannot be used
478 in any other contexts.
482 The `if', the `while', and the `for' statements
483 may be used to alter the flow within programs or to cause iteration.
484 The range of each of them is a statement or
485 a compound statement consisting of a collection of
486 statements enclosed in braces.
487 They are written in the following way
490 if(relation) statement
491 if(relation) statement else statement
492 while(relation) statement
493 for(expression1; relation; expression2) statement
499 if(relation) {statements}
500 if(relation) {statements} else {statements}
501 while(relation) {statements}
502 for(expression1; relation; expression2) {statements}
506 A relation in one of the control statements is an expression of the form
512 where two expressions are related by one of the six relational
513 operators `<', `>', `<=', `>=', `==', or `!='.
515 stands for `equal to' and `!=' stands for `not equal to'.
516 The meaning of the remaining relational operators is
519 BEWARE of using `=' instead of `==' in a relational. Unfortunately,
520 both of them are legal, so you will not get a diagnostic
521 message, but `=' really will not do a comparison.
523 The `if' statement causes execution of its range
524 if and only if the relation is true.
525 Then control passes to the next statement in sequence.
526 If an `else' branch is present, the statements in this branch are
527 executed if the relation is false.
528 The `else' keyword is a non-portable extension.
530 The `while' statement causes execution of its range
531 repeatedly as long as the relation
532 is true. The relation is tested before each execution
533 of its range and if the relation
534 is false, control passes to the next statement beyond the range
537 The `for' statement begins
538 by executing `expression1'. Then the relation is tested
539 and, if true, the statements in the range of the `for' are executed.
540 Then `expression2' is executed. The relation is tested, and so on.
541 The typical use of the `for' statement is for a controlled iteration,
545 for(i=1; i<=10; i=i+1) i
548 which will print the integers from 1 to 10.
549 Here are some examples of the use of the control statements.
555 for(i=1; i<=n; i=i+1) x=x*i
574 is a positive integer.
575 Here is the definition of a function which will
576 compute values of the binomial coefficient
577 (m and n are assumed to be positive integers).
583 for(j=1; j<=m; j=j+1) x=x*(n\-j+1)/j
588 The following function computes values of the exponential function
589 by summing the appropriate series
590 without regard for possible truncation errors:
615 There are some language features that every user should know
616 about even if he will not use them.
618 Normally statements are typed one to a line. It is also permissible
619 to type several statements on a line separated by semicolons.
621 If an assignment statement is parenthesized, it then has
622 a value and it can be used anywhere that an expression can.
623 For example, the line
629 not only makes the indicated assignment, but also prints the
632 Here is an example of a use of the value of an
633 assignment statement even when it is not parenthesized.
639 causes a value to be assigned to x and also increments i
640 before it is used as a subscript.
642 The following constructs work in BC in exactly the same manner
643 as they do in the C language. Consult the appendix or the
644 C manuals [2] for their exact workings.
648 x=y=z is the same as x=(y=z)
661 Even if you don't intend to use the constructs,
662 if you type one inadvertently, something correct but unexpected
665 Three Important Things
667 1. To exit a BC program, type `quit'.
669 2. There is a comment convention identical to that of C and
670 of PL/I. Comments begin with `/*' and end with `*/'.
671 As a non-portable extension, comments may also start with a `#' and end with
673 The newline is not part of the comment.
675 3. There is a library of math functions which may be obtained by
676 typing at command level
682 This command will load a set of library functions
683 which, at the time of writing, consists of sine (named `s'),
684 cosine (`c'), arctangent (`a'), natural logarithm (`l'),
685 exponential (`e') and Bessel functions of integer order (`j(n,x)'). Doubtless more functions will be added
687 The library sets the scale to 20. You can reset it to something
689 The design of these mathematical library routines
690 is discussed elsewhere [3].
698 BC will read and execute the named file or files before accepting
699 commands from the keyboard. In this way, you may load your
700 favorite programs and function definitions.
704 The compiler is written in YACC [4]; its original
705 version was written by S. C. Johnson.
709 K. Thompson and D. M. Ritchie,
711 UNIX Programmer's Manual,
719 The C Programming Language,
725 A Library of Reference Standard Mathematical Subroutines,
727 Bell Laboratories internal memorandum, 1975.
731 YACC \(em Yet Another Compiler-Compiler.
733 Bell Laboratories Computing Science Technical Report #32, 1978.
735 R. Morris and L. L. Cherry,
737 DC \- An Interactive Desk Calculator.
749 In the following pages syntactic categories are in \fIitalics\fP;
750 literals are in \fBbold\fP; material in brackets [\|] is optional.
754 Tokens consist of keywords, identifiers, constants, operators,
756 Token separators may be blanks, tabs or comments.
757 Newline characters or semicolons separate statements.
761 Comments are introduced by the characters /* and terminated by
763 As a non-portable extension, comments may also start with a # and
765 The newline is not part of the comment.
769 There are three kinds of identifiers \- ordinary identifiers, array identifiers
770 and function identifiers.
771 All three types consist of single lower-case letters.
772 Array identifiers are followed by square brackets, possibly
773 enclosing an expression describing a subscript.
774 Arrays are singly dimensioned and may contain up to 2048
776 Indexing begins at zero so an array may be indexed from 0 to 2047.
777 Subscripts are truncated to integers.
778 Function identifiers are followed by parentheses, possibly enclosing arguments.
779 The three types of identifiers do not conflict;
780 a program can have a variable named \fBx\fP,
781 an array named \fBx\fP and a function named \fBx\fP, all of which are separate and
786 The following are reserved keywords:
804 Constants consist of arbitrarily long numbers
805 with an optional decimal point.
806 The hexadecimal digits \fBA\fP\-\fBF\fP are also recognized as digits with
807 values 10\-15, respectively.
811 The value of an expression is printed unless the main
812 operator is an assignment.
813 The value printed is assigned to the special variable \fBlast\fP.
814 A single dot may be used as a synonym for \fBlast\fP.
815 This is a non-portable extension.
816 Precedence is the same as the order
817 of presentation here, with highest appearing first.
818 Left or right associativity, where applicable, is
819 discussed with each operator.
822 Primitive expressions
826 Named expressions are
827 places where values are stored.
829 named expressions are legal on the left
830 side of an assignment.
831 The value of a named expression is the value stored in the place named.
835 Simple identifiers are named expressions.
836 They have an initial value of zero.
838 \fIarray-name\fP\|[\|\fIexpression\fP\|]
840 Array elements are named expressions.
841 They have an initial value of zero.
843 \fBscale\fR, \fBibase\fR and \fBobase\fR
845 The internal registers
846 \fBscale\fP, \fBibase\fP and \fBobase\fP are all named expressions.
847 \fBscale\fP is the number of digits after the decimal point to be
848 retained in arithmetic operations.
849 \fBscale\fR has an initial value of zero.
850 \fBibase\fP and \fBobase\fP are the input and output number
852 Both \fBibase\fR and \fBobase\fR have initial values of 10.
856 \fIfunction-name\fB\|(\fR[\fIexpression\fR\|[\fB,\|\fIexpression\|\fR.\|.\|.\|]\|]\fB)
858 A function call consists of a function name followed by parentheses
859 containing a comma-separated list of
860 expressions, which are the function arguments.
861 A whole array passed as an argument is specified by the
862 array name followed by empty square brackets.
863 All function arguments are passed by
865 As a result, changes made to the formal parameters have
866 no effect on the actual arguments.
867 If the function terminates by executing a return
868 statement, the value of the function is
869 the value of the expression in the parentheses of the return
870 statement or is zero if no expression is provided
871 or if there is no return statement.
873 sqrt\|(\|\fIexpression\fP\|)
875 The result is the square root of the expression.
876 The result is truncated in the least significant decimal place.
877 The scale of the result is
878 the scale of the expression or the
885 length\|(\|\fIexpression\fP\|)
887 The result is the total number of significant decimal digits in the expression.
888 The scale of the result is zero.
890 scale\|(\|\fIexpression\fP\|)
892 The result is the scale of the expression.
893 The scale of the result is zero.
897 Constants are primitive expressions.
901 An expression surrounded by parentheses is
902 a primitive expression.
903 The parentheses are used to alter the
913 The result is the negative of the expression.
915 ++\|\fInamed-expression\fP
917 The named expression is
919 The result is the value of the named expression after
922 \-\-\|\fInamed-expression\fP
924 The named expression is
926 The result is the value of the named expression after
929 \fInamed-expression\fP\|++
931 The named expression is
933 The result is the value of the named expression before
936 \fInamed-expression\fP\|\-\-
938 The named expression is
940 The result is the value of the named expression before
943 Exponentiation operator
945 The exponentiation operator binds right to left.
947 \fIexpression\fP ^ \fIexpression\fP
949 The result is the first
950 expression raised to the power of the
952 The second expression must be an integer.
954 is the scale of the left expression
955 and \fIb\fP is the absolute value
956 of the right expression,
957 then the scale of the result is:
959 min\|(\|\fIa\(mub\fP,\|max\|(\|\fBscale\fP,\|\fIa\fP\|)\|)
961 Multiplicative operators
963 The operators *, /, % bind left to right.
965 \fIexpression\fP * \fIexpression\fP
967 The result is the product
968 of the two expressions.
969 If \fIa\fP and \fIb\fP are the
970 scales of the two expressions,
971 then the scale of the result is:
973 min\|(\|\fIa+b\fP,\|max\|(\|\fBscale\fP,\|\fIa\fP,\|\fIb\fP\|)\|)
975 \fIexpression\fP / \fIexpression\fP
977 The result is the quotient of the two expressions.
978 The scale of the result is the value of \fBscale\fR.
980 \fIexpression\fP % \fIexpression\fP
982 The % operator produces the remainder of the division
983 of the two expressions.
985 \fIa\fP%\fIb\fP is \fIa\fP\-\fIa\fP/\fIb\fP*\fIb\fP.
987 The scale of the result is the sum of the scale of
988 the divisor and the value of
995 The additive operators bind left to right.
997 \fIexpression\fP + \fIexpression\fP
999 The result is the sum of the two expressions.
1000 The scale of the result is
1001 the maximum of the scales of the expressions.
1003 \fIexpression\fP \- \fIexpression\fP
1005 The result is the difference of the two expressions.
1006 The scale of the result is the
1007 maximum of the scales of the expressions.
1009 assignment operators
1011 The assignment operators bind right to left.
1013 \fInamed-expression\fP = \fIexpression\fP
1015 This expression results in assigning the value of the expression
1017 to the named expression on the left.
1019 \fInamed-expression\fP += \fIexpression\fP
1021 \fInamed-expression\fP \-= \fIexpression\fP
1023 \fInamed-expression\fP *= \fIexpression\fP
1025 \fInamed-expression\fP /= \fIexpression\fP
1027 \fInamed-expression\fP %= \fIexpression\fP
1029 \fInamed-expression\fP ^= \fIexpression\fP
1031 The result of the above expressions is equivalent
1032 to ``named expression = named expression OP expression'',
1033 where OP is the operator after the = sign.
1037 Unlike all other operators, the relational operators
1038 are only valid as the object of an \fBif\fP, \fBwhile\fP,
1039 or inside a \fBfor\fP statement.
1041 \fIexpression\fP < \fIexpression\fP
1043 \fIexpression\fP > \fIexpression\fP
1045 \fIexpression\fP <= \fIexpression\fP
1047 \fIexpression\fP >= \fIexpression\fP
1049 \fIexpression\fP == \fIexpression\fP
1051 \fIexpression\fP != \fIexpression\fP
1055 There are only two storage classes in BC, global and automatic
1057 Only identifiers that are to be local to a function need be
1058 declared with the \fBauto\fP command.
1059 The arguments to a function
1060 are local to the function.
1061 All other identifiers are assumed to be global
1062 and available to all functions.
1063 All identifiers, global and local, have initial values
1065 Identifiers declared as \fBauto\fP are allocated on entry to the function
1066 and released on returning from the function.
1067 They therefore do not retain values between function calls.
1068 \fBauto\fP arrays are specified by the array name followed by empty square brackets.
1070 Automatic variables in BC do not work in exactly the same way
1071 as in either C or PL/I. On entry to a function, the old values of
1072 the names that appear as parameters and as automatic
1073 variables are pushed onto a stack.
1074 Until return is made from the function, reference to these
1075 names refers only to the new values.
1079 Statements must be separated by semicolon or newline.
1080 Except where altered by control statements, execution
1083 Expression statements
1085 When a statement is an expression, unless
1086 the main operator is an assignment, the value
1087 of the expression is printed, followed by a newline character.
1091 Statements may be grouped together and used when one statement is expected
1092 by surrounding them with { }.
1094 Quoted string statements
1098 This statement prints the string inside the quotes.
1102 \fBif\|(\|\fIrelation\fB\|)\|\fIstatement\fR
1104 The substatement is executed if the relation is true.
1108 \fBif\|(\|\fIrelation\fB\|)\|\fIstatement\fB\|else\|\fIstatement\fR
1110 The first substatement is executed if the relation is true, the second
1111 substatement if the relation is false.
1112 The \fBif-else\fR statement is a non-portable extension.
1116 \fBwhile\|(\|\fIrelation\fB\|)\|\fIstatement\fR
1118 The statement is executed while the relation
1120 The test occurs before each execution of the statement.
1124 \fBfor\|(\|\fIexpression\fB; \fIrelation\fB; \fIexpression\fB\|)\|\fIstatement\fR
1126 The \fBfor\fR statement is the same as
1130 \fBwhile\|(\fPrelation\|\fB) {\fP
1137 All three expressions may be left out.
1138 This is a non-portable extension.
1144 \fBbreak\fP causes termination of a \fBfor\fP or \fBwhile\fP statement.
1150 \fBcontinue\fP causes the next iteration of a \fBfor\fP or \fBwhile\fP
1151 statement to start, skipping the remainder of the loop.
1152 For a \fBwhile\fP statement, execution continues with the evaluation
1154 For a \fBfor\fP statement, execution continues with evaluation of
1155 the last-expression.
1156 The \fBcontinue\fP statement is a non-portable extension.
1160 \fBauto \fIidentifier\fR\|[\|\fB,\fIidentifier\fR\|]
1162 The \fBauto\fR statement causes the values of the identifiers to be pushed down.
1163 The identifiers can be ordinary identifiers or array identifiers.
1164 Array identifiers are specified by following the array name by empty square
1166 The auto statement must be the first statement
1167 in a function definition.
1172 \fBdefine(\|\fR[\fIparameter\|\fR[\fB\|,\|\fIparameter\|.\|.\|.\|\fR]\|]\|\fB)\|{\fI
1176 The \fBdefine\fR statement defines a function.
1178 be ordinary identifiers or array names.
1179 Array names must be followed by empty square brackets.
1180 As a non-portable extension, the opening brace may also appear on the
1187 \fBreturn(\fI\|expression\|\fB)\fR
1189 The \fBreturn\fR statement causes termination of a function,
1190 popping of its auto variables, and
1191 specifies the result of the function.
1192 The first form is equivalent to \fBreturn(0)\fR.
1193 The result of the function is the result of the expression
1195 Leaving out the expression between parentheses is equivalent to
1197 As a non-portable extension, the parentheses may be left out.
1201 The \fBprint\fR statement takes a list of comma-separated expressions.
1202 Each expression in the list is evaluated and the computed
1203 value is printed and assigned to the variable `last'.
1204 No trailing newline is printed.
1205 The expression may also be a string enclosed in double quotes.
1206 Within these strings the following escape sequences may be used:
1216 for carriage return,
1220 for double quote and
1223 Any other character following a backslash will be ignored.
1224 Strings will not be assigned to `last'.
1225 The \fBprint\fR statement is a non-portable extension.
1229 The \fBquit\fR statement stops execution of a BC program and returns
1230 control to UNIX when it is first encountered.
1231 Because it is not treated as an executable statement,
1233 in a function definition or in an