vb.netquickbasic

Way to Jump to Next i in For..Next Loop?


I'm reverse engineering in QuickBasic and I have code like this:

FOR i = star TO fin
   IF a < 1 THEN 
    CALL clrbot
    COLOR 15
    PRINT force$(side); " army in "; city$(armyloc(i)); " is CUT OFF !";
    TICK turbo!
    GOTO alone
   END IF
   size = size + 1
   max = 11: IF LEN(armyname$(i)) < 11 THEN max = LEN(armyname$(i))
   mtx$(size) = LEFT$(armyname$(i), max)
   array(size) = i
alone:
NEXT i

I'd like to get rid of the line label (alone) and instead do something like:

   IF a < 1 THEN 
     CALL clrbot
    COLOR 15
    PRINT force$(side); " army in "; city$(armyloc(i)); " is CUT OFF !";
    TICK turbo!
    NEXT i
   END IF

Solution

  • You could replace the GOTO with an Else:

    For i = star To Fin
        If a < 1 Then
            ' Do something
        Else
            ' Do Something else
        End If
    Next
    

    This would follow the same logic - the Else takes the place of the GOTO alone statement.

    In the original code (QuickBASIC) if the If block is entered, everything after then GOTO alone statement is ignored.

    If the If block is not entered (i.e., a >= 1) then everything after the If block is executed.

    The Else statement in the VB.NET code will produce the same behavior. If a < 1, the first block will be executed and the Else block will be ignored, and the loop will advance to the next increment of i.

    If a >= 1, then the Else block will be executed and the loop will then advance to the next increment of i.

    The above assumes labels in QuickBASIC are like labels in DOS batch files.