• Tutorials

  • Home
  • GPDL $BREAK Keyword

    Transfers control to the first statement after the current loop or switch structure.

    For example, its use in a looping structure:



    $WHILE ($LISTEN() != "")

    {

    $IF ($LISTENTEXT() == "BYE")

    {

    $BREAK;

    };

    DoSomethingWithListenText();

    };



    In this example, we ask the player to enter some text. We want to stop asking for text if the player enters an empty line or if he enters the word “BYE”. The $WHILE condition terminates the loop if the player enters an empty line. We use the “$BREAK” to 'break out of the loop' if the player enters the text “BYE”. There are other ways of accomplishing this example but the way shown is relatively straight-forward and contains no complicated Boolean expressions.



    Example in a switch/case structure:



    $SWITCH ( class )

    {

    $CASE “HUMAN” ; HP = 12; $BREAK;

    $CASE “IRISH”” : HP = 11; $BREAK;

    $CASE “ITALIAN”; HP = 10; $BREAK;

    $DEFAULT: HP = 1; BREAK;

    };



    The $SWITCH begins executing statements with the first $CASE that matches. Then it would normally execute all the statements after that. For example, if the class were “IRISH” then, without the $BREAK keywords, we would execute HP=11, HP=10, and HP=1. That is not our intent. We wanted only to execute HP=11. So we added the $BREAK keywords to 'Break Out' of the switch structure as soon as we have executed the code for the case that matches.