mIRC Home    About    Download    Register    News    Help

Print Thread
#175814 29/04/07 02:12 AM
N
nataliad
nataliad
N
I dont understand the meaning of "while loop"

who can explain me please in simple words
(using a pseudocode maybe)

thanks smile

#175816 29/04/07 02:22 AM
Joined: Dec 2002
Posts: 1,997
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 1,997
Code:
alias whiletest {
  var %i = 1
  while (%i < 20) {
    echo -a %i
    inc %i
  }
  echo -a 20 reached
}


In the example above, as long as %i is less than 20 the
script will keep looping, once 20 is reached the loop breaks
and continues with the rest of the script. As you can see,
the value of %i is increased with each loop.

#175847 29/04/07 05:14 PM
Joined: Oct 2005
Posts: 1,671
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,671
The principle of a while loop is that "while" the case inside the () brackets is true, the commands inside the {} brackets will be executed. You can think of it as an IF statement that keeps happening until the (statement) is $false. You usually see while-loops used to loop through a series of numbers. However, they can be used for anything where the code needs to be repeated until a statement is met. If the statement contains variables, they are usually changed (set/incremented/decremented) from within the loop's command section (as the example above). You could also have identifiers in the statement (like $ctime). While-loops, in other languages, have more uses than in mIRC (such as physical delays). Such delays can't be used in mIRC as they lock up the GUI.

Code:
while (statement is not false) {
  execute these commands
  and these commands
}


-genius_at_work


Link Copied to Clipboard