<p class="Paragraph">Sorgt dafür, daß das Programm innerhalb einer Unterroutine (Sub) oder einer Funktion (Function) mit der Abarbeitung des Programmteils fortfährt, der durch eine Marke gekennzeichnet ist.</p>
<p class="Paragraph">Mit Hilfe der <span class="T1">GoTo</span>-Anweisung weisen Sie <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> Basic an, mit der Programmausführung an einem ganz anderen Teil des <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> Basic-Programms innerhalb einer Unterroutine (Sub) oder Funktion (Function) fortzufahren. Die Stelle, an der das Programm mit der Ausführung fortfahren soll, ist mit einer Marke gekennzeichnet. Um eine Marke zu setzen, benennen Sie sie beliebig und schließen Sie mit einem Doppelpunkt (":") ab.</p>
<p class="TextInTable">Bitte beachten Sie, daß Sie mit der GoTo-Anweisung niemals aus einem Unterprogramm oder einer Funktion hinausspringen dürfen.</p>
<p class="TextInTable">Die <span class="T1">GoTo</span>-Anweisung ist ein Relikt älterer Basicdialekte, die nur aus Kompatibilitätsgründen erhalten geblieben sind. Verwenden Sie GoTo sehr häufig, wird Ihr Programm für Sie, aber auch für andere Programmierer, schwer lesbar. Versuchen Sie sich daher einen Programmstil anzueignen, der möglichst wenig, am besten gar keinen Gebrauch der <span class="T1">GoTo</span>-Anweisung macht. Einzige Ausnahmen sind <span class="T1">On...GoTo</span> und <span class="T1">On Error GoTo</span> (siehe dort).</p>
</span></th></tr></table>
<p class="Paragraph"/>
<p class="Paragraph">Beispiel:</p>
<p class="PropText">Sub ExampleOnGosub </p>
<p class="PropText">Dim iVar As Integer </p>
<p class="PropText">Dim sVar As String </p>
<p class="PropText">iVar = 2 </p>
<p class="PropText">sVar ="" </p>
<p class="PropText">On iVar GoSub Sub1, Sub2 </p>
<p class="PropText">On iVar GoTo Line1, Line2 </p>
<p class="PropText">Exit Sub </p>
<p class="PropText">Sub1: </p>
<p class="PropText">sVar =sVar & <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>" Von Sub 1 nach" : Return </p>
<p class="PropText">Sub2: </p>
<p class="PropText">sVar =sVar & <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>" Von Sub 2 nach" : Return </p>
<p class="PropText">Line1: </p>
<p class="PropText">sVar =sVar & <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>" Marke 1" </p>
<p class="PropText">Line2: </p>
<p class="PropText">sVar =sVar & <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>" Marke 2" </p>