Goto loops: Difference between revisions

From Scriptwiki
Jump to navigation Jump to search
m cleaning wanted pages-list
 
mNo edit summary
 
(8 intermediate revisions by 3 users not shown)
Line 2: Line 2:
Goto's aren't used very much.
Goto's aren't used very much.


  alias testmsg {
  [[alias]] channels {
   if ($1 == ahihi) { goto ahihi }
   [[var]] %i , %chans
   elseif ($1 == kiaa) { goto kiaa }
  :nexti
   else { echo -ag try again! }
  [[inc]] %i
  [[if]] (%i > [[$chan]](0)) { [[return]] %chans }
  var %chans = %chans $chan(%i)
  [[Goto loops|goto]] nexti
}
 
Sometimes you may wish to use goto not in connection with 'loops', an example of which is below:
alias Eat {
   if ([[$istok]](Apples Pears Nothing,$1,32)) goto [[$1-|$1]]
  [[echo]] -at *** You don't fancy anything to eat? I don't know what $1 is.
  return
  :Apples
   echo -at *** You just ate an apple!
  return
   
   
   :ahihi
   :Pears
   msg #channel ahihi
   echo -at *** You just ate a pear!
   halt
   return
   
   
   :kiaa
   :Nothing
   msg #channel kiaa
   echo -at *** Not hungry? You haven't eaten anything.
  halt
  }
  }
== See Also ==
* [[While loops]]
[[Category:Commands]]

Latest revision as of 08:09, 2 July 2007

You can use goto command to jump from one point to another in a script.
Goto's aren't used very much.

alias channels {
  var %i , %chans 
  :nexti
  inc %i
  if (%i > $chan(0)) { return %chans }
  var %chans = %chans $chan(%i)
  goto nexti
}

Sometimes you may wish to use goto not in connection with 'loops', an example of which is below:

alias Eat {
  if ($istok(Apples Pears Nothing,$1,32)) goto $1
  echo -at *** You don't fancy anything to eat? I don't know what $1 is.
  return

  :Apples
  echo -at *** You just ate an apple!
  return

  :Pears
  echo -at *** You just ate a pear!
  return

  :Nothing
  echo -at *** Not hungry? You haven't eaten anything.
}

See Also