|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > STK. - Stack > STK.-Management > Stack Management Commands |
MiniRobotLanguage (MRL)
STK.Count
Get the number of items in the stack
Intention
The STK.Count command is used to retrieve the number of items currently stored in a stack. This is particularly useful when you need to iterate through the stack or check if the stack is empty before performing operations.
The command returns the item count in the specified variable (e.g., $$CNT). If the result variable is omitted, the count is placed on the Top of Stack (TOS).
Syntax
STK.Count|P1[|P2]
Parameter Explanation
P1 - The stack handle. This is typically a variable that contains the handle of the stack.
P2 - (Optional) The variable to store the item count. If omitted, the result is placed on the Top of Stack (TOS).
Example
'***********************************
' STK.Count - Sample Script
'***********************************
' Create a new stack
STK.New|$$STK
' Push some items onto the stack
STK.Push|$$STK|Item1
STK.Push|$$STK|Item2
STK.Push|$$STK|Item3
' Get the number of items in the stack
STK.Count|$$STK|$$CNT
DBP. Number of items in stack: $$CNT
' End the stack
STK.End|$$STK
ENR.
Remarks
-
Limitations:
-
See also:
• STK.New - Create a new stack
• STK.Push - Push an item onto the stack
• STK.Pop - Pop an item from the stack