pozition of subroutines

Hello,
I am coming from MIkroBasik.
On that language you must have a strict position on the program for subroutine.
Let me explain:
Let's say i am in a subroutine A where i have to do 4-5 times the same calculation to get a data.
Because the portion of code is repeated 4-5 time, i decided to make a new subroutine.
So every time when the code arrive at the repeating point has to jump to the new subroutine, execute and return back on the premier one.
The bad part with Mikrobasic is that you MUST to put this new subroutine ABOVE THE ORIGINAL ONE.
If you put it bellow, it return an error.
What is the rule here.
The subroutine you call, can be positioned anywhere ?
Thank you

In C/C++, the rule is basically the same.

void blink()
{
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(1000);
}

void setup()
{
  pinMode(13, OUTPUT);
}

void loop()
{
  blink();
}

However, you can use function prototypes before the point where you need to call the function and move the function to where you want it.

// function prototype
void blink();

void setup()
{
  pinMode(13, OUTPUT);
}

void loop()
{
  blink();
}

// blink implementation here
void blink()
{
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(1000);
}

Now the IDE has some tricks up its sleeve and does the adding of the prototypes for you when you verify. It might however get it wrong at occasion.

// function prototype removed
//void blink();

void setup()
{
  pinMode(13, OUTPUT);
}

void loop()
{
  blink();
}

// blink implementation here
void blink()
{
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(1000);
}

You can also put all prototypes in an include file and include that file in the sketch.

In C++ you must either put your function definition above where you call it or provide a prototype ( q.v.). The Arduino IDE tries to make your life easier by providing prototypes invisibly for you so it doesn't matter where you put the function definitions.