Duck hunt
/ /

XtScript: Goto

How to make a loop function in XtScript using Goto

goto ("Go to") is a command in XtScript to jump to certain jump point declared in the script.

The jump point used in Goto command is declared using @ prefix.

goto is a command that most useful for creating loop function in XtScript.

Learn XtScript Goto from examples

Creating a simple loop by make use of if and goto in xtscript

- Code:
<!--parser:xtscript-->
	var $number = 0
	var $limit = 10

	@add_number
	var $number = ($number + 1)

	if $number <= $limit
		print Number now = $number <br/>
		goto @add_number
	else
		goto @end_loop
	endif
	@end_loop
<!--/parser:xtscript-->
- Result:
Number now = 1
Number now = 2
Number now = 3
Number now = 4
Number now = 5
Number now = 6
Number now = 7
Number now = 8
Number now = 9
Number now = 10
Loop through a series of subtraction and print only even numbers

<!--parser:xtscript-->
	var $number = 25

	@subtract_number
	var $number = ($number - 1)

	if ($number % 2) == 0
		print Found even number: $number <br/>
		goto @subtract_number
	elseif $number > 1
		goto @subtract_number
	else
		goto @end_loop
	endif

	@end_loop
	print <p>"Operation complete"</p>
<!--/parser:xtscript-->
- Result:
Found even number: 24
Found even number: 22
Found even number: 20
Found even number: 18
Found even number: 16
Found even number: 14
Found even number: 12
Found even number: 10
Found even number: 8
Found even number: 6
Found even number: 4
Found even number: 2

"Operation complete"