|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > STK. - Stack > STK.Operations > Stack Operations |
MiniRobotLanguage (MRL)
STK.Add|$$STK[|$$NUM]
Add the top $$NUM elements, remove them, and push the result onto the stack.
Intention
The STK.Add command takes the top $$NUM elements from the stack, calculates their sum, removes them from the stack, and pushes the resulting value onto the stack.
If $$NUM is omitted, the default value is 2, and the top two elements are added together.
Syntax
STK.Add|$$STK[|$$NUM]
Parameter Explanation
P1 - $$STK: The stack handle where the elements are added and manipulated.
P2 - $$NUM (Optional): The number of elements to add. If omitted, the default is 2.
Example
'***********************************
' Example 1: Add Top 2 Elements
'***********************************
STK.New|$$STK
STK.Push|$$STK|5
STK.Push|$$STK|10
STK.Add|$$STK
STK.Pop|$$STK|$$RES
JIV.$$RES!15|Lab_Failed
STK.End|$$STK
ENR.
'***********************************
' Example 2: Add Top 3 Elements
'***********************************
STK.New|$$STK
STK.Push|$$STK|2
STK.Push|$$STK|4
STK.Push|$$STK|6
STK.Add|$$STK|3
STK.Pop|$$STK|$$RES
JIV.$$RES!12|Lab_Failed
STK.End|$$STK
ENR.
Remarks
- The elements are removed from the stack after they are added.
- If $$NUM is greater than the number of elements in the stack, an error will occur.
Limitations:
- The stack handle must be valid before calling STK.Add. Invalid handles will result in an error.
See also:
• STK.New
• STK.End