From: me AT here DOT com Newsgroups: comp.os.msdos.djgpp,comp.os.msdos.programmer Subject: Re: Iteration vs. Recursion... Date: 23 Jul 1999 19:27:39 GMT Organization: Plug 'n' Pray! Lines: 72 Message-ID: <7nafnb$rp4$3@schbbs.mot.com> References: <7n7s1h$ms6$1 AT autumn DOT news DOT rcn DOT net> NNTP-Posting-Host: css08u.seattle.css.mot.com User-Agent: tin/pre-1.4-19990216 ("Styrofoam") (UNIX) (SunOS/5.6 (sun4u)) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com if (kbhit() { switch (c = getch()) { case 'a': /* do something */ break; case 'b': /* etc */ break; default: break; } } Also, while recursion allows you to write short an nice code in many cases, it should be avoided in most of those cases because if something runs amok recursion can quickly exhaust memory and cause all sort of troubles. In comp.os.msdos.programmer Tom wrote: > I have a keyboard input program that runs one thing if one key is entered > and another if another key is entered. There are about ten different > options. That means I have ten different if statements. I am using > recursion because after I get one input I do the program over again. > The only problem with this program is that I have to hold down the key for > about a second before anything is recognized. Is there any way to speed > this up? Possibly by using iteration instead of recursion. Here is the > code. Any suggestions are greatly appreciated. I left out the program > names and variables not needed. I use getch to catch the keystrokes. I > tried using the bioskey but that didn't speed anything up. I am using DJGPP > to compile this: > /*********start code******** > { > if (getch() == x) > {run_program(); > run_program(); > exit(0);} > if (getch() == y) > run_program(); > if (getch() == z) > run_program(); > if (getch() == a) > run_program(); > if (getch() == b) > run_program(); > if (getch() == c) > run_program(); > if (getch() == d) > run_program(); > if (getch() == e) > {run_program(); > if ((getch() == f || (getch() == g)) > run_program(); > if (getch() == h) > run_program(); > if (getch() == i) > run_program(); > } > ****end code**********/ > Thanks. > Tom