locked
Infinite Loop Problem RRS feed

  • Question

  • The following program creates a Number relative to a person's Age in a given year. As programmed it gives results for two years in a row.

    SigYear = 1980
    age = 27
    mob = "Aug"

    calculateN()
    Print2Screen()

    SigYear = SigYear+1
    age = age+1
    calculateN()
    Print2Screen()

    Sub calculateN
      plus1 = SigYear + 1
      index = SigYear + age
      N = 0
      For i = 1 To 4
        total = Text.GetSubText(index, i, 1)
        N = N + total
      EndFor
    EndSub

    Sub Print2Screen
      TextWindow.WriteLine("From " +  mob + " " + SigYear + " to " + mob + " " + plus1 + " the number is " + N)
      TextWindow.WriteLine("")
    EndSub
     

    I'd like to have it show results for a longer period, say a decade. But if I set

    SigYear = SigYear+1
    age = age+1
    calculateN()
    Print2Screen()

    in a For I = 1 To 10

    EndFor

    nesting,  OR do the same with

    calculateN()
    Print2Screen()
    SigYear = SigYear+1
    age = age+1

    the program goes into an infinite loop.

    Can someone tell me why? What am I doing wrong?

    Buckfast Burro

    Wednesday, March 27, 2013 12:12 PM

Answers

  • Variables are Global , i.e. the i in your main program and in the Calculate subroute interfere. Give one another name e.g. j or i1.

    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Buckfast Burro Wednesday, March 27, 2013 7:37 PM
    Wednesday, March 27, 2013 3:06 PM
    Answerer

All replies

  • Variables are Global , i.e. the i in your main program and in the Calculate subroute interfere. Give one another name e.g. j or i1.

    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Buckfast Burro Wednesday, March 27, 2013 7:37 PM
    Wednesday, March 27, 2013 3:06 PM
    Answerer
  • Thank you, Jan. You are right and I hadn't even noticed!!

    Buckfast

    Wednesday, March 27, 2013 7:36 PM