Complexity analysis of while loop with two conditions
As Patrick87 pointed out. The first loop is $\min(m,n)$.  As for your extended question,   it's unclear if you want best, worst, or average case.  We typically look at worst case.  Either way, you seem to be focused on a single execution when you really need consider all possible $i$ and $j$ values.  So, let's do that:


$m = n$.  


In this case the additional conditional does no work, so the total run time is still $O(\min(m,n))$.


$m &lt; n$.  


When this is true, then the first loop terminates due to $j$. The conditional will then carry out the first case $i &lt; n$ and terminate after $O(n-m)$ iterations.  The total number of operations is then $O(n-m+m)= O(n)$ operations.


$m &gt; n$.


This case is equivalent to the second case but the result is $O(m)$. 

Now observe that cases 1,2, &amp; 3 are all equivalent to $O(\max(m,n))$. This is the running time for your code.  

So back to your "how to" question. You need to do a good, thorough case analysis for multi-conditional loops just like you need to do with conditionals.  Then analyze the running time of each case and, assuming your doing worst case analysis, take the largest running time.