Answered by:
How Recursive Functions works ?
Question

Answers

Indeed, when a function is called, its return memory address is stored within the stack.
But the closer that Small Basic has of a function is a subroutine!!!
This is not not a C# forum! @_@
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
 Proposed as answer by Ed Price  MSFTMicrosoft employee, Owner Thursday, October 11, 2012 6:09 AM
 Marked as answer by Ed Price  MSFTMicrosoft employee, Owner Friday, October 19, 2012 5:26 PM

This is a sample of recursive call in Small Basic. This code saves variables as array. You can use Stack also to save variables.
' Ice ' Copyright (c) 2010 Nonki Takahashi GraphicsWindow.BackgroundColor = "Gray" GraphicsWindow.PenColor = "White" level = 1 maxlevel = 5 xc[level] = GraphicsWindow.Width / 2 yc[level] = GraphicsWindow.Height / 2 arm[level] = 100 DrawIce() Sub DrawIce x1[level] = xc[level]  arm[level] x2[level] = xc[level] + arm[level] y1[level] = yc[level] y2[level] = yc[level] GraphicsWindow.DrawLine(x1[level], y1[level], x2[level], y2[level]) level = level + 1 arm[level] = arm[level  1] * 0.3 If level <= maxlevel Then xc[level] = x1[level  1] yc[level] = y1[level  1] DrawIce() ' recursive call xc[level] = x2[level  1] yc[level] = y2[level  1] DrawIce() ' recursive call EndIf level = level  1 x1[level] = xc[level] + arm[level] * Math.Cos(Math.Pi / 3) x2[level] = xc[level]  arm[level] * Math.Cos(Math.Pi / 3) y1[level] = yc[level] + arm[level] * Math.Sin(Math.Pi / 3) y2[level] = yc[level]  arm[level] * Math.Sin(Math.Pi / 3) GraphicsWindow.DrawLine(x1[level], y1[level], x2[level], y2[level]) level = level + 1 arm[level] = arm[level  1] * 0.3 If level <= maxlevel Then xc[level] = x1[level  1] yc[level] = y1[level  1] DrawIce() ' recursive call xc[level] = x2[level  1] yc[level] = y2[level  1] DrawIce() ' recursive call EndIf level = level  1 x1[level] = xc[level]  arm[level] * Math.Cos(Math.Pi / 3) x2[level] = xc[level] + arm[level] * Math.Cos(Math.Pi / 3) y1[level] = yc[level] + arm[level] * Math.Sin(Math.Pi / 3) y2[level] = yc[level]  arm[level] * Math.Sin(Math.Pi / 3) GraphicsWindow.DrawLine(x1[level], y1[level], x2[level], y2[level]) level = level + 1 arm[level] = arm[level  1] * 0.3 If level <= maxlevel Then xc[level] = x1[level  1] yc[level] = y1[level  1] DrawIce() ' recursive call xc[level] = x2[level  1] yc[level] = y2[level  1] DrawIce() ' recursive call EndIf level = level  1 EndSub
Nonki Takahashi
 Proposed as answer by Ed Price  MSFTMicrosoft employee, Owner Thursday, October 11, 2012 6:09 AM
 Marked as answer by Ed Price  MSFTMicrosoft employee, Owner Friday, October 19, 2012 5:26 PM
All replies

Indeed, when a function is called, its return memory address is stored within the stack.
But the closer that Small Basic has of a function is a subroutine!!!
This is not not a C# forum! @_@
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
 Proposed as answer by Ed Price  MSFTMicrosoft employee, Owner Thursday, October 11, 2012 6:09 AM
 Marked as answer by Ed Price  MSFTMicrosoft employee, Owner Friday, October 19, 2012 5:26 PM

This is a sample of recursive call in Small Basic. This code saves variables as array. You can use Stack also to save variables.
' Ice ' Copyright (c) 2010 Nonki Takahashi GraphicsWindow.BackgroundColor = "Gray" GraphicsWindow.PenColor = "White" level = 1 maxlevel = 5 xc[level] = GraphicsWindow.Width / 2 yc[level] = GraphicsWindow.Height / 2 arm[level] = 100 DrawIce() Sub DrawIce x1[level] = xc[level]  arm[level] x2[level] = xc[level] + arm[level] y1[level] = yc[level] y2[level] = yc[level] GraphicsWindow.DrawLine(x1[level], y1[level], x2[level], y2[level]) level = level + 1 arm[level] = arm[level  1] * 0.3 If level <= maxlevel Then xc[level] = x1[level  1] yc[level] = y1[level  1] DrawIce() ' recursive call xc[level] = x2[level  1] yc[level] = y2[level  1] DrawIce() ' recursive call EndIf level = level  1 x1[level] = xc[level] + arm[level] * Math.Cos(Math.Pi / 3) x2[level] = xc[level]  arm[level] * Math.Cos(Math.Pi / 3) y1[level] = yc[level] + arm[level] * Math.Sin(Math.Pi / 3) y2[level] = yc[level]  arm[level] * Math.Sin(Math.Pi / 3) GraphicsWindow.DrawLine(x1[level], y1[level], x2[level], y2[level]) level = level + 1 arm[level] = arm[level  1] * 0.3 If level <= maxlevel Then xc[level] = x1[level  1] yc[level] = y1[level  1] DrawIce() ' recursive call xc[level] = x2[level  1] yc[level] = y2[level  1] DrawIce() ' recursive call EndIf level = level  1 x1[level] = xc[level]  arm[level] * Math.Cos(Math.Pi / 3) x2[level] = xc[level] + arm[level] * Math.Cos(Math.Pi / 3) y1[level] = yc[level] + arm[level] * Math.Sin(Math.Pi / 3) y2[level] = yc[level]  arm[level] * Math.Sin(Math.Pi / 3) GraphicsWindow.DrawLine(x1[level], y1[level], x2[level], y2[level]) level = level + 1 arm[level] = arm[level  1] * 0.3 If level <= maxlevel Then xc[level] = x1[level  1] yc[level] = y1[level  1] DrawIce() ' recursive call xc[level] = x2[level  1] yc[level] = y2[level  1] DrawIce() ' recursive call EndIf level = level  1 EndSub
Nonki Takahashi
 Proposed as answer by Ed Price  MSFTMicrosoft employee, Owner Thursday, October 11, 2012 6:09 AM
 Marked as answer by Ed Price  MSFTMicrosoft employee, Owner Friday, October 19, 2012 5:26 PM