From: toudi Newsgroups: comp.os.msdos.djgpp,comp.os.msdos.programmer Subject: Re: Iteration vs. Recursion... Date: Thu, 22 Jul 1999 22:40:29 +0200 Organization: beautiful piramids Lines: 71 Sender: pienkny AT pc73 DOT warszawa DOT ppp DOT tpnet DOT pl Message-ID: <379781BD.74785239@friko6.onet.pl> References: <7n7s1h$ms6$1 AT autumn DOT news DOT rcn DOT net> NNTP-Posting-Host: pc73.warszawa.ppp.tpnet.pl Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 8bit X-Trace: news.onet.pl 932675925 3560 212.160.54.73 (22 Jul 1999 20:38:45 GMT) X-Complaints-To: abuse AT onet DOT pl NNTP-Posting-Date: 22 Jul 1999 20:38:45 GMT X-Mailer: Mozilla 4.5 [pl] (Win95; I) X-Accept-Language: pl To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Tom napisał(a): > 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 use a 'switch' char ch = getch(); switch (ch) { case 'a': run_prog(); break; case 'b': run(); break; case 'c': run(); break; } -- mailto:pienkny AT friko6 DOT onet DOT pl +4822368951