From WikiChip
Difference between revisions of "mirc/commands/while"
m (Bot: Fixing links) |
|||
(13 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | The '''/ | + | {{mirc title|/while Command}} |
+ | The '''/while command''' is a [[While Loops - mIRC|construct in the mIRC scripting language]] that can perform repetitive operations. The block of statement inside the while loop will get executed as long as the condition is true. You can manually break out of a loop by using the Cltr+Break key combinations. | ||
== Synopsis == | == Synopsis == | ||
Line 15: | Line 16: | ||
== Example == | == Example == | ||
− | <syntaxhighlight lang="mIRC">/ | + | How to iterate over lines of a file |
− | + | <syntaxhighlight lang="mIRC"> | |
+ | ;Read all lines of a file: | ||
+ | var %file file.txt | ||
+ | var %i 1 | while (%i <= $lines(%file)) { | ||
+ | echo -a line %i - $read(%file,nt,%i) | ||
+ | inc %i | ||
+ | } | ||
+ | |||
+ | ;Read from line 5 and stop at line 10: | ||
+ | var %file file.txt | ||
+ | var %i 5 | while (%i <= $lines(%file)) { | ||
+ | echo -a line %i - $read(%file,nt,%i) | ||
+ | if (%i == 10) break | ||
+ | inc %i | ||
+ | } | ||
+ | |||
+ | ;Note: These are the code snippets that you should use inside your alias or script. | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | Other examples of using a loop | ||
+ | |||
+ | Example 1: | ||
+ | <syntaxhighlight lang="mIRC"> | ||
+ | ;Example 1 | ||
+ | |||
Alias CountToTen { | Alias CountToTen { | ||
;Create a counter variable, set it to one | ;Create a counter variable, set it to one | ||
Line 49: | Line 75: | ||
<syntaxhighlight lang="mIRC"> | <syntaxhighlight lang="mIRC"> | ||
− | + | ;Example 2 | |
− | |||
Alias ListVars { | Alias ListVars { | ||
Line 79: | Line 104: | ||
== Compatibility == | == Compatibility == | ||
− | + | {{mIRC compatibility|5.7}} | |
− | |||
− | |||
− | |||
− | |||
− | |||
== See also == | == See also == | ||
Line 96: | Line 116: | ||
{{mIRC command list}} | {{mIRC command list}} | ||
− | [[Category: | + | [[Category:mIRC commands|while command - mIRC]] |
Latest revision as of 06:58, 29 December 2023
Commands & Identifiers
Basics
Events
Matching Tools
Data Storage
Control Structures
GUI Scripting
Sockets
Advanced Scripting
Additional Resources
Security
Other
The /while command is a construct in the mIRC scripting language that can perform repetitive operations. The block of statement inside the while loop will get executed as long as the condition is true. You can manually break out of a loop by using the Cltr+Break key combinations.
Synopsis[edit]
while (condition) { /statements /statements /statements }
Switches[edit]
None
Parameters[edit]
None
Example[edit]
How to iterate over lines of a file
;Read all lines of a file: var %file file.txt var %i 1 | while (%i <= $lines(%file)) { echo -a line %i - $read(%file,nt,%i) inc %i } ;Read from line 5 and stop at line 10: var %file file.txt var %i 5 | while (%i <= $lines(%file)) { echo -a line %i - $read(%file,nt,%i) if (%i == 10) break inc %i } ;Note: These are the code snippets that you should use inside your alias or script.
Other examples of using a loop
Example 1:
;Example 1 Alias CountToTen { ;Create a counter variable, set it to one var %Counter = 1 ;Loop while the counter variable is less than or equal to ten. while (%Counter <= 10) { ;Print out the value of the counter variable echo -a Count Number: %Counter ;Increase the counter variable by 1 inc %Counter } }
The above example will output:
Count Number: 1 Count Number: 2 Count Number: 3 Count Number: 4 Count Number: 5 Count Number: 6 Count Number: 7 Count Number: 8 Count Number: 9 Count Number: 10
Example 2:
;Example 2 Alias ListVars { ;Check if there are any variables set if (!$var(*,0)) { echo -a There Are No Variables. halt } ;Set a counter variable var %a 1 ;Loop while the counter variable is less than or equal to the total number of variables while (%a <= $var(*,0)) { ;Print out the variable and its value echo -a $v1 $+ ) $var(*,$v1) = $var(*,$v1).value ;Increase the variable by one inc %a } }
The above example will output something like this:
1) %Foo = FooBar 2) %Bar = BarFoo
Compatibility[edit]
Added: mIRC v5.7
Added on: 02 Feb 2000
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.
See also[edit]
mIRC commands list