The word "mientras" in Spanish introduces a subordinate clause that expresses an action that is taking place at the same time as another (while) or a condition that is needed to fulfil the action in the main clause (as long as).
Let's see some examples:
Notice how in all the examples above we are using "mientras". However, in the first two examples "mientras" is followed by El Presente and it is translated as "while".
In the last two examples "mientras" is followed by El Presente de Subjuntivo and it is translated by "as long as".
Let's see the difference between these two nearly identical sentences:
Vemos tu programa favorito, mientras tú preparas la cena.
We watch your favourite program while you make dinner.
Vemos tu programa favorito, mientras tú prepares la cena.
We'll watch your favourite program as long as you make dinner.
In the first example where we use El Presente (preparas) there are two actions happening at the same time (watching his favourite programme and making dinner).
In the second sentence where we use El Presente de Subjuntivo (prepares), the action in the main clause (watching his favourite programme) happens only if the condition expressed with "mientras" is fulfilled (only if he makes dinner).
Here is another example to compare:
In the sentence above two actions happen at the same time (El Presente)
Here, there is a condition to fulfil the action (El Presente de Subjuntivo )
Note that we can also use "siempre que..." or "mientras que..."with the same meaning as "mientras" (as long as). For example:
Te invito a un café mientras me ayudes a estudiar después.
Te invito a un café mientras que me ayudes a estudiar después.
Te invito a un café siempre que me ayudes a estudiar después.
I'll buy you a coffee as long as you help me study later.
Sometimes, in sentences using the future tense in the main clause, mientras could also mean while when followed by the subjunctive. In this case, we will be talking about two actions that may happen at the same time. For example:
The meaning of this sentence could be:
1. Lola will dance as long as we sing. (only if we sing she will dance)
2. Lola will dance while we sing. (for as long as/while we sing she will dance -two possible actions happening at the same time)