none
IF loop not working RRS feed

  • Question

  • The last 8 lines are what I am having trouble with. The first FOR loop only goes through once before the program ends. Is there a solution or a way to get this to work? 

    TextWindow.WriteLine("How many alternatives are there?")
    Alternative = TextWindow.ReadNumber()
    TextWindow.WriteLine("How many states of nature are there?")
    State_Nature = TextWindow.ReadNumber()
    For i = 1 To Alternative 
      TextWindow.WriteLine("Enter the alternative: ")
      Alternative_A[i] = TextWindow.Read()
    EndFor
    For i = 1 To State_Nature
      TextWindow.WriteLine("Enter the state of nature: ")
      State_Nature_A[i] = TextWindow.Read()
      For i = 1 To Alternative 
        TextWindow.WriteLine("Enter the payoff of the state of nature: ")
        Payoff[i] = TextWindow.ReadNumber()
      EndFor
    EndFor


    • Edited by Persds Thursday, January 18, 2018 2:11 PM
    Thursday, January 18, 2018 2:10 PM

Answers

  • You are using the same variable 'i' for the inner and outer loop - when the second loop is complete I > State_Nature and this loop is done.

    Use for example variable j for inner loop:

    For j = 1 To Alternative

    Thursday, January 18, 2018 2:52 PM
    Moderator

All replies

  • You are using the same variable 'i' for the inner and outer loop - when the second loop is complete I > State_Nature and this loop is done.

    Use for example variable j for inner loop:

    For j = 1 To Alternative

    Thursday, January 18, 2018 2:52 PM
    Moderator
  • That worked!
    Thursday, January 18, 2018 3:37 PM