From WikiChip
Editing mirc/while loops

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 1: Line 1:
 
{{mirc title|While Loops}}
 
{{mirc title|While Loops}}
In many occasions, you may end up doing a task over and over again in a single script (For example, counting from 0 to 10, or sending a message to multiple people or channels). A '''while loop''' is a control flow statement that allows code to be executed repeatedly based on a given condition. The code inside the while loop block will get executed as long as the condition is true.
+
In many occasions, you may end up doing a task over and over again in a single script (For example, counting from 0 to 10, or sending a message to multiple people or channels). A '''while loop''' is a control flow statement that allows code to be executed repeatedly based on a given condition. The code inside the while loop block will get executed as long as the condition is {{mIRC|$true}}.
  
 
== Syntax ==
 
== Syntax ==
Line 16: Line 16:
 
#If the statement was false.<br />No code inside the while loop is executed and the script skips right down to any code below it.
 
#If the statement was false.<br />No code inside the while loop is executed and the script skips right down to any code below it.
  
=== true conditions ===
+
=== {{mIRC|$true}} conditions ===
So we said the while loop will continue to iterate as long as the condition is true. But what exactly does that mean? In mSL, a condition is true if the outcome of the condition is NOT 0, {{mIRC|$null}}, or {{mIRC|$false}}. For example let %x be 5, if the condition is while ({{mIRC|$calc}}(%x - 5)) {, since 5-5 is 0, the while loop's condition is false, thus it will not execute any code inside it.
+
So we said the while loop will continue to iterate as long as the condition is {{mIRC|$true}}. But what exactly does that mean? In mSL, a condition is true if the outcome of the condition is NOT 0, {{mIRC|$null}}, or {{mIRC|$false}}. For example let %x be 5, if the condition is while ({{mIRC|$calc}}(%x - 5)) {, since 5-5 is 0, the while loop's condition is false, thus it will not execute any code inside it.
 
 
'''Note''': If you are using an operator, for example while (0 == 0) {, the operator is going to define if the condition is true or not, 0 being equal to 0, this condition is true.
 
  
 
==== Example 1 ====
 
==== Example 1 ====

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)