Path: utzoo!mnetor!uunet!husc6!wjh12!maynard!campbell From: campbell@maynard.BSW.COM (Larry Campbell) Newsgroups: comp.lang.c Subject: Re: gotos Message-ID: <1075@maynard.BSW.COM> Date: 22 Apr 88 14:30:47 GMT References: <1988Apr8.183815.3187@utzoo.uucp> <449@goofy.megatest.UUCP> <1988Apr11.201934.20594@utzoo.uucp> <748@l.cc.purdue.edu> <3470@bunker.UUCP> <2200@louie.udel.EDU> Reply-To: campbell@maynard.UUCP (Larry Campbell) Organization: The Boston Software Works, Inc. Lines: 56 In article <2200@louie.udel.EDU> new@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@maynard.bsw.com 120 Fulton Street, Boston MA 02109 uucp: {husc6,mirror,think}!maynard!campbell +1 617 367 6846