Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// var w, h int
	for scanner.Scan() {
		// fmt.Scanf("%d %d", &w, &h)

		input := strings.Split(scanner.Text(), " ")
		w, _ := strconv.Atoi(input[0])
		h, _ := strconv.Atoi(input[1])

		if w == 0 && h == 0 {
			return
		}

		isArrive := make([][]bool, w)
		tiles := make([][]string, w)

		for i := 0; i < w; i++ {
			rowArrive := make([]bool, h)
			rowTiles := make([]string, h)
			scanner.Scan()
			row := scanner.Text()
			for j := 0; j < h; j++ {
				rowTiles[j] = string(row[j])
			}
			tiles[i] = rowTiles
			isArrive[i] = rowArrive
		}

		var i, j int
		isEnd := false
		for {
			if isArrive[i][j] == true {
				fmt.Println("LOOP")
				break
			}
			isArrive[i][j] = true

			switch tiles[i][j] {
			case ">":
				j++
			case "^":
				i--
			case "v":
				i++
			case "<":
				j--
			case ".":
				isEnd = true
			}

			if isEnd == true {
				fmt.Println(j, i)
				break
			}
		}
	}
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <climits>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>

using namespace std;

int main() {
    int H, W;
    while (cin >> H >> W && (H || W)) {
        vector<string> tiles(H, string(W, ' '));
        for (int i=0; i<H; ++i) {
            for (int j=0; j<W; ++j) {
                cin >> tiles[i][j];
            }
        }

        int x = 0, y = 0;
        int visited[101][101] = {false};
        while ( ! visited[y][x]) {
            visited[y][x] = true;
            switch (tiles[y][x]) {
                case '>':
                    x ++;
                    break;
                case '<':
                    x --;
                    break;
                case 'v':
                    y ++;
                    break;
                case '^':
                    y --;
                    break;
            }
        }
        if (tiles[y][x] == '.') {
            cout << x << " " << y << endl;
        } else {
            cout << "LOOP" << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int *array1, *array2, n, m, tmp, i, j;
	char w;
	
	while(1){
		cin >> n >> m;
		if(n == 0 || m == 0){
			break;
		}
		if(n*m > 2){
			array1 = (int *)calloc(n*m+1, sizeof(int));
			array2 = (int *)calloc(n*m+1, sizeof(int));
		} else {
			array1 = (int *)calloc(2, sizeof(int));
			array2 = (int *)calloc(2, sizeof(int));
		}
		
		for(i = 0; i < n; i++){
			for(j = 0, tmp = i*m; j < m; j++){
				cin >> w;
				if(tmp < 0){
				break;
				}
				if(w == '>'){
					array1[tmp+j] = tmp + j + 1;
				} else if(w == 'v'){
					array1[tmp+j] = tmp + j + m;
				} else if(w == '<'){
					array1[tmp+j] = tmp + j -1;
				} else if(w == '^'){
					array1[tmp+j] = tmp + j - m;
				} else {
					array1[tmp+j] = -1;
				}
			}
			if(tmp < 0){
				break;
			}
		}
		if(tmp < 0){
			cout << "LOOP" << endl;
			free(array1);
			free(array2);
			continue;
		}
		
		tmp = array1[0];
		array2[0] = 1;
		while(1){
			if(array2[tmp] == 1){
				cout << "LOOP" << endl;
				break;
			} else if(array1[tmp] == -1){
				i = tmp % m;
				j = (int)(tmp / m);
				cout << i << " " << j << endl;
				break;
			}
			
			array2[tmp] = 1;
			tmp = array1[tmp];
		}		
		
		free(array1);
		free(array2);
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

string comp(int x, int y)
{
	stringstream ss;

	ss << x << " " << y;

	return ss.str();
}

string rec(vector<string>& field, pint pos)
{
	int buf = field[pos.first][pos.second];
	field[pos.first][pos.second] = 0;
	
	switch(buf)
	{
	case '.' :
		return comp(pos.second, pos.first);
		
	case '>' :
		return rec(field, mp(pos.first, pos.second + 1));

	case '<' :
		return rec(field, mp(pos.first, pos.second - 1));

	case '^' :
		return rec(field, mp(pos.first - 1, pos.second));

	case 'v' :
		return rec(field, mp(pos.first + 1, pos.second));

	default :
		return "LOOP";
	}
}

int main()
{
	int w, h;
	while(cin >> h >> w && w)
	{
		vector<string> field(h);

		rep(i, h)
			cin >> field[i];

		cout << rec(field, mp(0, 0)) << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int H, W;
  while (cin >> H >> W, H) {
    string s[110];
    bool used[110][110] = {};
    for (int i = 0; i < H; i++) {
      cin >> s[i];
    }
    int y = 0, x = 0;
    bool loop = false;
    while (true) {
      if (used[y][x]) {
        loop = true;
        break;
      }
      used[y][x] = true;
      if (s[y][x] == '>') x++;
      else if (s[y][x] == '<') x--;
      else if (s[y][x] == '^') y--;
      else if (s[y][x] == 'v') y++;
      else break;
    }
    if (loop) cout << "LOOP" << endl;
    else cout << x << " " << y << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;


int w,h;

int map[10001];
bool visited[10001];

int move(int pos) {

  if(visited[pos]==true) return -1;

  else {

    visited[pos]=true;

    switch(map[pos]) {

    case 0:
      return pos;

    case 1:
      return move(pos+1);

    case 2:
      return move(pos-w);

    case 3:
      return move(pos-1);

    case 4:
      return move(pos+w);

    }

  }

  return -1;

}

int main() {

  string buf;

  int res;
  

  while(cin >> h >> w) {

    if(w==0 && h==0) break;

    getline(cin,buf);

    for(int i=0;i<10001;i++) visited[i]=false;

    for(int i=0;i<h;i++) {

      getline(cin,buf);

      for(int j=0;j<w;j++) {

	switch(buf[j]) {

	case '.':
	  map[i*w+j]=0;
	  break;

	case '>':
	  map[i*w+j]=1;
	  break;

	case '^':
	  map[i*w+j]=2;
	  break;

	case '<':
	  map[i*w+j]=3;
	  break;

	case 'v':
	  map[i*w+j]=4;
	  break;

	}

      }

    }
    /*
    for(int i=0;i<h;i++) {

      for(int j=0;j<w;j++) {

	cout << map[i*w+j];

      }

      cout << endl;

    }
    */
    res=move(0);

    if(res==-1) cout << "LOOP" << endl;

    else cout << res%w << " " << res/w << endl;
    
  }

  return 0;

}