Results 1 to 5 of 5

Thread: Quick Question

  1. #1
    Join Date
    Mar 2009
    Location
    Antaractica, Penguin Drive
    Posts
    140
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Quick Question

    What is forward and how is it used? Eg:

    SCAR Code:
    procedure Moo; forward;
    procedure Meow;
    begin
      WriteLn('Meow!');
    end;

    In the example what would the forward do?

  2. #2
    Join Date
    Mar 2009
    Location
    Illinois
    Posts
    292
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ok this is how i understand it:

    Let say you have
    SCAR Code:
    procedure eh;
    begin
      case randomnumber(1, 2) of
         1: bafa;
         2: blah;
      end;
    end;
    So you'll need this:
    SCAR Code:
    function randomnumber(min, max: integer): integer;
    begin
      result :=  random(max)+1;
    end;
    but in your actual script the function "randomnumber" is below the procedure in which you wish to call it in. So you'll have to forward it:
    SCAR Code:
    program new;
    function randomnumber(min, max: integer); forward;
    procedure eh;
    begin
      case randomnumber(1, 2) of
         1: bafa;
         2: blah;
      end;
    end;
    function randomnumber(min, max: integer): integer;
    begin
      result :=  random(max)+1;
    end;
    make sence?

    And in that example it would do jack haha

  3. #3
    Join Date
    Mar 2009
    Location
    Antaractica, Penguin Drive
    Posts
    140
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ok thanks that makes sense I just don't see why you don't put the function before the procedure but otherwise thanks

  4. #4
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    If you need it after because you use the one above, it would be impossible to do with just two.

    So that is why you use forward. I'll write up an example in a second.

    SCAR Code:
    program New;

    procedure Test2; forward;

    procedure Test1;
    begin
    end;

    procedure Test2;
    begin
      Test1;
    end;

    begin
      Test1;
    end.

    Delete the forward line and see what happens .
    Last edited by Da 0wner; 07-16-2009 at 04:15 AM.

  5. #5
    Join Date
    Mar 2009
    Location
    Antaractica, Penguin Drive
    Posts
    140
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •