Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!ll-xn!ames!pasteur!ucbvax!decwrl!decvax!gsg!lew From: lew@gsg.UUCP (Paul Lew) Newsgroups: comp.lang.c Subject: Re: gotos Message-ID: <144@gsg.UUCP> Date: 21 Apr 88 15:57:55 GMT References: <2200@louie.udel.EDU> Organization: General Systems Group, Inc., Salem, NH Lines: 57 > 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': ... > ... > } > > I contend that if the reading and formatting and displaying are sufficiently > slow, such behaviour can be desirable (i.e., on microcomputers). > I would like to see a goto-less version of this that is easier to understand. I think judicious use of goto is ok, but in this example, I think the following code is easier to understand than your code. The block stucture and ESPECIALLY indentation make it easier to understand, I have to read your version line by line to figure out what it does. int kp = 0; /* keypress indicator */ for (i = 0; i < max_in_table && key != name[i]; ++i) if (kp = keypressed()) break; if (!kp) { seek(helpfile, offset[i]); if (!keypressed()) { linecount = 0; do { read_line_from_file(); ++linecount; if (keypressed() || read_line[0] == special_flag_char) break; insert_spaces_and_color_codes(); if (keypressed()) break; display_text_line(); if (keypressed()) break; } while (linecount < 24); } } c = wait_for_key_then_read_it(); switch (c) { case 'A': ... ... -- Paul Lew {oliveb,harvard,decvax}!gsg!lew (UUCP) General Systems Group, 5 Manor Parkway, Salem, NH 03079 (603) 893-1000