Stack Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > STK. - Stack > STK.Operations >

Stack Operations

STK.Dup

Previous Top Next


MiniRobotLanguage (MRL)

 

STK.Dup

Duplicate the top element $$NUM times and push them onto the stack

 

 

Intention

 

The STK.Dup command is used to duplicate the top element of the stack a specified number of times. This is useful when you need to create multiple copies of the same value for further processing or manipulation. The command works with all stack types (String, Integer, Float).

If the optional parameter $$NUM is omitted, the top element is duplicated once by default.

 

 

Syntax

 

STK.Dup|$$STK[|$$NUM]

 

 

Parameter Explanation

 

P1 - $$STK The stack handle, typically a numeric value or a variable that contains a number from 0 to 1024.

P2 - $$NUM (optional) The number of times the top element should be duplicated. If omitted, the default value is 1.

 

 

Example

 

'***********************************

' STK.Dup - Sample Script

'***********************************

' Create a new stack

STK.New|$$STK|s

' Push a value onto the stack

STK.Push|$$STK|Hello

' Duplicate the top element 3 times

STK.Dup|$$STK|3

' Pop and display the duplicated elements

STK.Pop|$$STK|$$RES

DBP.$$RES

STK.Pop|$$STK|$$RES

DBP.$$RES

STK.Pop|$$STK|$$RES

DBP.$$RES

STK.Pop|$$STK|$$RES

DBP.$$RES

' End the script

ENR.

 

 

Remarks

 

-

 

 

Limitations:

- The stack must not be empty when using this command.

 

See also:

 

STK.Push

STK.Pop

STK.Count