Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!uwm.edu!bionet!ucselx!crash!kevin@crash.cts.com From: kevin@crash.cts.com (Kevin Hill) Newsgroups: comp.sys.mac.programmer Subject: For Loops, Summary Message-ID: <6968@crash.cts.com> Date: 16 Jan 91 08:50:53 GMT Sender: root@crash.cts.com Lines: 43 I was pleasantly surprised today, Wednesday Morning 1:10am, to find my mailbox, full of letters telling me that I forgot to initialize 'i' in the code that I posted earlier. However, I do assure you, that I was initialized... I finally gave up and defined the 8 positions of surround by typing each case out. Oh, well. Also, many Kudo's to Tom Shores who told me to get rid of the blob of programming I had, and use the following if ((gx+k<0)||(gx+k>GXMAX)||(gy-j<0)||(gy-j>GYMAX)) surround[i] = -1; Wheeeew, I didn't know I could smash all my code into that two line peice of if for loop! Yowzers inspector gadget! I'll have to call on Tom to omptimize my program that I am writing for me! Thanks to everyone who wrote, if you know of any bugs in Think C 3.01p4, that involve for loops, please tell me because the problem that I am having, is something that should not happen. Also, all the variables, are initialized and surround is defined as a int surround[9]; variable. here's the code again, for those who missed it > > for(j = -1;j < 2;j++) > { > > for(k = -1;k < 2;k++) > { > printf("%3d %3d\t",j,k); > i++; > surround[i] = track[gx+k][gy+j]; > if ( (gx+k) < 0) > surround[i] = -1; > if ( (gx+k) > GXMAX) > surround[i] = -1; > if ( (gy-j) < 0) > surround[i] = -1; > if ( (gy-j) > GYMAX) > surround[i] = -1; > } > > } The problem seems to be that the variables j and k do wild things after they do what is expected of them. Then they go off to change the correct value of surround[9] to something wierd and go off into lala land.