gotos

Darren New new at udel.EDU
Thu Apr 21 15:19:43 AEST 1988


In article <3470 at bunker.UUCP> garys at bunker.UUCP (Gary M. Samuelson) writes:
>In article <748 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>>
>>Here is a challenge to the denigrators of goto.
>> ...
>
>Now give me something hard.
>
>Gary Samuelson

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.
                             - Darren New
                               Graduate Student
                               University of Delaware.

   



More information about the Comp.lang.c mailing list