Monday 1 December 2014

Infinite loops

In week 11 Danny went over functions that loop forever. In my computer science courses in high school, and in csc108, it is stressed that one should never make a program that loops infinitely. Either by accident or on purpose. The only way for the computer to end the loop is if it runs out of memory and the program crashes, which is also bad. This has already been a problem writing programs for my csc108 course. My partner once accidentally created an infinite loop, and the program promptly crashed after attempting to run it. It is also difficult to determine if a program is looping infinitely or just taking a very long time to run. When attempting to solve a problem in the 108 assignment I created a triple nested loop that would eventually return the correct answer. However, because there were three loops to go through, the program took a long time to run with large inputs and was not efficient. I eventually had to rewrite the program because the run time was sometimes longer than 5 minutes, but it would eventually return a value.
I found this was one of the problems with thinking about programs that have infinite loops. How is it possible to tell if  a program is simply taking a long time to return a value, or is it looping infinitely.
Danny talked about writing a function to determine if a program loops infinitely by testing it with another program. I don't quite understand how a program could test if a program loops infinitely, because calling on a function that loops will cause it to loop infinitely so it would never return anything, and the program testing it would be waiting for a return value for an infinite amount of time.

3 comments:

  1. Infinite loop was quiet hard for me to understand. But now, it's no problem to me!

    ReplyDelete
  2. I had same experience as you before when I took 108 last year.

    ReplyDelete
  3. Yep, when the instructor talked about this, it really reminded me of 108 as well. This course is related to more things than previously imagined eh

    ReplyDelete