220 Creating and Running Algorithms Chapter 6
Comment Lines Probably the most important element of programming is the comment.
In older BASIC interpreters the comment line began with "REM" and
ended at the end-of-line character(s) (probably carriage return then
linefeed). Later BASICs allowed comments to also begin with various
"shorthand" characters such as "!" or "'". In all cases, a comment ended
when the end-of-line is encountered. In 'C' and the Algorithm Language,
comments begin with the two characters "/*" and continue until the two
characters "*/" are encountered. Examples:
/* this line is solely a comment line */
if ( a != b) c = d + 1; /* comment within a code line */
/* This comment is composed of more than one line.
The comment can be any number of lines long and
terminates when the following two characters appear
*/
About the only character combination that is not allowed within a comment
is "*/", since this will terminate the comment.
if(a <= 0) c=abs(a);
if(a != 0)
c = b / a;
if((a != b) && (a != c))
{a = a * b;
b = b + 1;
c = 0;
}
if((a == 5) || (b == -5))
{c = abs(c);
c = 2 / c;
}
else
{c = a * b;
}
IF A<=0 THEN C=ABS(A)
IF A<>0 THEN
C=B/A
END IF
IF A<>B AND A<>C THEN
A=A*B
B=B+1
C=0
END IF
IF A=5 OR B=-5 THEN
C=ABS(C)
C= 2/C
ELSE
C= A*B
END IF
ExamplesBASIC Syntax 'C' Syntax
Figure 6-6. Examples of 'C' and BASIC If Statements