none
the Goto in the Else of the If statement not working correctly RRS feed

  • Question

  • Hi,

    the Else Goto Retry1 in this code doesn't work and the program just ends. The only ones that work correctly is

    If type1 = "+" Then
      type()
    Else 
      Goto retry1
    EndIf

    If Text.ConvertToLowerCase(userretry1) = "reset" Then
      Goto Start
    Elseif Text.ConvertToLowerCase(userretry1) = "end" Then
      Program.End()
    Else
      Goto retry1
    Endif 

    This is the whole code

    FYI this is me just messing with If Statements and Sub statements that is why it looks bad :)

    Goto Start
    retry1:
    TextWindow.Clear()
    TextWindow.WriteLine("Input Not Recognized")
    TextWindow.WriteLine("Try Again")
    TextWindow.WriteLine(" ")
    TextWindow.WriteLine("Type (Reset) to Reset Program")
    TextWindow.WriteLine("Type (End) to End Program")
    TextWindow.WriteLine(" ")
    userretry1 = TextWindow.Read()
    If Text.ConvertToLowerCase(userretry1) = "reset" Then
      Goto Start
    Elseif Text.ConvertToLowerCase(userretry1) = "end" Then
      Program.End()
    Else
      Goto retry1
    Endif 
    Goto Start
    con1:
    TextWindow.Clear()
    TextWindow.WriteLine("Type (Reset) to Reset Program")
    TextWindow.WriteLine("Type (End) to End Program")
    TextWindow.WriteLine(" ")
    userretry1 = TextWindow.Read()
    If Text.ConvertToLowerCase(userretry1) = "reset" Then
      Goto Start
    Elseif Text.ConvertToLowerCase(userretry1) = "end" Then
      Program.End()
    Else
      Goto retry1
    Endif 
    Start:
    TextWindow.Clear()
    type1 = TextWindow.Read()
    If type1 = "+" Then
      type()
    Else 
      Goto retry1
    EndIf
    Sub type 
      TextWindow.WriteLine("How many are you adding together")
      type2 = TextWindow.ReadNumber()
      If type2 = "2" Then
        twoa()
      ElseIf type2 = "3" Then
        threea()
      Else
        Goto retry1
      EndIf
    EndSub
    Sub twoa
      TextWindow.WriteLine("Number 1")
      onena = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 2")
      twona = TextWindow.ReadNumber()
      ANS2A = onena+twona
      TextWindow.WriteLine("Your answer is " + ANS2A)
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Type (Con) to Continue")
      TextWindow.WriteLine(" ")
      usercon1 = TextWindow.Read()
      If Text.ConvertToLowerCase(usercon1) = "con" Then
        Goto con1
      Else 
        Goto retry1
      EndIf
    EndSub
    Sub threea
      TextWindow.WriteLine("Number 1")
      onena1 = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 2")
      twona1 = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 3")
      threena1 = TextWindow.ReadNumber()
      ANS2A1 = onena1+twona1+threena1
      TextWindow.WriteLine("Your answer is " + ANS2A1)
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Type (Con) to Continue")
      TextWindow.WriteLine(" ")
      usercon2 = TextWindow.Read()
      If Text.ConvertToLowerCase(usercon2) = "con" Then
        Goto con1
      Else 
        Goto retry1
      EndIf
    EndSub


    I love coding. This is signature is 100% Original. :)

    Saturday, February 11, 2017 7:44 PM

Answers

  • SELF ANSWERED!

    Instead of using Goto I replaced it with a Sub statement instead

    Start()
    Sub Retry1
    TextWindow.Clear()
    TextWindow.WriteLine("Input Not Recognized")
    TextWindow.WriteLine("Try Again")
    TextWindow.WriteLine(" ")
    TextWindow.WriteLine("Type (Reset) to Reset Program")
    TextWindow.WriteLine("Type (End) to End Program")
    TextWindow.WriteLine(" ")
    userretry1 = TextWindow.Read()
    If Text.ConvertToLowerCase(userretry1) = "reset" Then
      Start()
    Elseif Text.ConvertToLowerCase(userretry1) = "end" Then
      Program.End()
    Else
      Retry1()
    Endif 
    EndSub
    Sub Con1
    TextWindow.Clear()
    TextWindow.WriteLine("Type (Reset) to Reset Program")
    TextWindow.WriteLine("Type (End) to End Program")
    TextWindow.WriteLine(" ")
    userretry1 = TextWindow.Read()
    If Text.ConvertToLowerCase(userretry1) = "reset" Then
      Start()
    Elseif Text.ConvertToLowerCase(userretry1) = "end" Then
      Program.End()
    Else
      Retry1()
    Endif 
    EndSub
    Sub Start
    TextWindow.Clear()
    type1 = TextWindow.Read()
    If type1 = "+" Then
      type()
    Else 
      Retry1()
    EndIf
    EndSub
    Sub type 
      TextWindow.WriteLine("How many are you adding together")
      type2 = TextWindow.ReadNumber()
      If type2 = "2" Then
        twoa()
      ElseIf type2 = "3" Then
        threea()
      Else
        Retry1()
      EndIf
    EndSub
    Sub twoa
      TextWindow.WriteLine("Number 1")
      onena = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 2")
      twona = TextWindow.ReadNumber()
      ANS2A = onena+twona
      TextWindow.WriteLine("Your answer is " + ANS2A)
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Type (Con) to Continue")
      TextWindow.WriteLine(" ")
      usercon1 = TextWindow.Read()
      If Text.ConvertToLowerCase(usercon1) = "con" Then
        Con1()
      Else 
        Retry1()
      EndIf
    EndSub
    Sub threea
      TextWindow.WriteLine("Number 1")
      onena1 = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 2")
      twona1 = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 3")
      threena1 = TextWindow.ReadNumber()
      ANS2A1 = onena1+twona1+threena1
      TextWindow.WriteLine("Your answer is " + ANS2A1)
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Type (Con) to Continue")
      TextWindow.WriteLine(" ")
      usercon2 = TextWindow.Read()
      If Text.ConvertToLowerCase(usercon2) = "con" Then
        Con1()
      Else 
        Retry1()
      EndIf
    EndSub

    Now it works fine

    If you are using Goto change 

    name: to Sub name

    EndSub

    and Goto name to name()

    Example

    Start()

    Sub Start TextWindow.WriteLine("Type (Slip) to skip)") user = TextWindow.Read() If Text.ConvertToLowerCase(user) = "skip" Then name() Else retry() EndIf EndSub Sub name TextWindow.Writeline("Skipped") EndSub Sub retry TextWindow.Writeline("Input Not Recognized") Program.Delay(5000) Start() EndSub




    I love coding. This is signature is 100% Original. :)




    Saturday, February 11, 2017 8:00 PM

All replies

  • SELF ANSWERED!

    Instead of using Goto I replaced it with a Sub statement instead

    Start()
    Sub Retry1
    TextWindow.Clear()
    TextWindow.WriteLine("Input Not Recognized")
    TextWindow.WriteLine("Try Again")
    TextWindow.WriteLine(" ")
    TextWindow.WriteLine("Type (Reset) to Reset Program")
    TextWindow.WriteLine("Type (End) to End Program")
    TextWindow.WriteLine(" ")
    userretry1 = TextWindow.Read()
    If Text.ConvertToLowerCase(userretry1) = "reset" Then
      Start()
    Elseif Text.ConvertToLowerCase(userretry1) = "end" Then
      Program.End()
    Else
      Retry1()
    Endif 
    EndSub
    Sub Con1
    TextWindow.Clear()
    TextWindow.WriteLine("Type (Reset) to Reset Program")
    TextWindow.WriteLine("Type (End) to End Program")
    TextWindow.WriteLine(" ")
    userretry1 = TextWindow.Read()
    If Text.ConvertToLowerCase(userretry1) = "reset" Then
      Start()
    Elseif Text.ConvertToLowerCase(userretry1) = "end" Then
      Program.End()
    Else
      Retry1()
    Endif 
    EndSub
    Sub Start
    TextWindow.Clear()
    type1 = TextWindow.Read()
    If type1 = "+" Then
      type()
    Else 
      Retry1()
    EndIf
    EndSub
    Sub type 
      TextWindow.WriteLine("How many are you adding together")
      type2 = TextWindow.ReadNumber()
      If type2 = "2" Then
        twoa()
      ElseIf type2 = "3" Then
        threea()
      Else
        Retry1()
      EndIf
    EndSub
    Sub twoa
      TextWindow.WriteLine("Number 1")
      onena = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 2")
      twona = TextWindow.ReadNumber()
      ANS2A = onena+twona
      TextWindow.WriteLine("Your answer is " + ANS2A)
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Type (Con) to Continue")
      TextWindow.WriteLine(" ")
      usercon1 = TextWindow.Read()
      If Text.ConvertToLowerCase(usercon1) = "con" Then
        Con1()
      Else 
        Retry1()
      EndIf
    EndSub
    Sub threea
      TextWindow.WriteLine("Number 1")
      onena1 = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 2")
      twona1 = TextWindow.ReadNumber()
      TextWindow.WriteLine("Number 3")
      threena1 = TextWindow.ReadNumber()
      ANS2A1 = onena1+twona1+threena1
      TextWindow.WriteLine("Your answer is " + ANS2A1)
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Type (Con) to Continue")
      TextWindow.WriteLine(" ")
      usercon2 = TextWindow.Read()
      If Text.ConvertToLowerCase(usercon2) = "con" Then
        Con1()
      Else 
        Retry1()
      EndIf
    EndSub

    Now it works fine

    If you are using Goto change 

    name: to Sub name

    EndSub

    and Goto name to name()

    Example

    Start()

    Sub Start TextWindow.WriteLine("Type (Slip) to skip)") user = TextWindow.Read() If Text.ConvertToLowerCase(user) = "skip" Then name() Else retry() EndIf EndSub Sub name TextWindow.Writeline("Skipped") EndSub Sub retry TextWindow.Writeline("Input Not Recognized") Program.Delay(5000) Start() EndSub




    I love coding. This is signature is 100% Original. :)




    Saturday, February 11, 2017 8:00 PM
  • Here is 2 little program that do the same: count 1 to 100, indefinitely

    But many programmer will say the While, endwhile loop is better programming practice.

    Why, i don't know ,cannot explain !

    ____________________________  first way ______________________________________

    start:
    For t=1 To 100
      TextWindow.WriteLine(t)
    EndFor
    Goto start

    __________________________ second way _______________________________________

    While 1=1
    For t=1 To 100
      TextWindow.WriteLine(t)
    EndFor
    EndWhile

    ____________________________________________________________________________

    Saturday, February 11, 2017 8:19 PM
    Answerer