gotos
Larry Campbell
campbell at maynard.BSW.COM
Sat Apr 23 00:30:47 AEST 1988
In article <2200 at louie.udel.EDU> new at udel.EDU (Darren New) writes:
<>How about: (pseudocode)
<> for (i = 0; i < max_in_table && key != name[i]; ++i)
<> if (keypressed()) goto handle_key;
<> seek(helpfile, offset[i]);
<> if (keypressed()) goto handle_key;
<> linecount = 0;
<> do {
<> read_line_from_file();
<> ++linecount;
<> if (keypressed()) goto handle_key;
<> if (read_line[0] == special_flag_char) goto handle_key;
<> insert_spaces_and_color_codes();
<> if (keypressed()) goto handle_key;
<> display_text_line();
<> if (keypressed()) goto handle_key;
<> } while (linecount < 24);
<> handle_key:
<> c = wait_for_key_then_read_it();
<> switch (c) {
<> case 'A': ...
<> ...
<> }
Use a signal handler. Example:
handle_key()
{
c = wait_for_key_then_read_it();
switch (c)
{
case 'A': ...
...
}
}
... main body of code:
signal(SIGIO, handler);
for (i = 0; i < max_in_table && key != name[i]; ++i)
;
seek(helpfile, offset[i]);
linecount = 0;
do {
read_line_from_file();
++linecount;
insert_spaces_and_color_codes();
display_text_line();
} while (linecount < 24);
This is not only much clearer and easier to read, it's also considerably
faster. And doesn't use gotos.
--
Larry Campbell The Boston Software Works, Inc.
Internet: campbell at maynard.bsw.com 120 Fulton Street, Boston MA 02109
uucp: {husc6,mirror,think}!maynard!campbell +1 617 367 6846
More information about the Comp.lang.c
mailing list