Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		l := strings.Split(stdin.Text(), " ")
		if l[0] == "0" {
			break
		}
		h, _ := strconv.Atoi(l[0])
		w, _ := strconv.Atoi(l[1])

		tile := make([][]rune, h)
		done := make([][]bool, h)
		for i := 0; i < h; i++ {
			stdin.Scan()
			s := stdin.Text()
			tile[i] = make([]rune, w)
			done[i] = make([]bool, w)
			for j, c := range s {
				tile[i][j] = c
			}
		}
		i, j := 0, 0
		for tile[i][j] != '.' {
			if done[i][j] {
				i = -1
				break
			}
			done[i][j] = true
			switch tile[i][j] {
			case '>':
				j++
			case '<':
				j--
			case '^':
				i--
			case 'v':
				i++
			}
		}
		if i < 0 {
			fmt.Println("LOOP")
		} else {
			fmt.Println(j, i)
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

int main() {

  int w, h;
  while( cin >> h >> w, w+h ) {
    char room[10][10];
    bool flag[10][10];
    int now_x = 0, now_y = 0;

    for(int i=0; i<h; i++) {
      for(int j=0; j<w; j++) {
	cin >> room[i][j];
	flag[i][j] = false;
      }
    }

    while(1) {
      if( flag[now_y][now_x] || room[now_y][now_x] == '.' ) break;
      char c = room[now_y][now_x];
      flag[now_y][now_x] = true;
     

      if( c == '>' ) {
	while( room[now_y][now_x] == c ) {
	  now_x++;
	}
      }
      if( c == '<' ) {
	while( room[now_y][now_x] == c ) {
	  now_x--;
	}
      }
      if( c == 'v' ) {
	while( room[now_y][now_x] == c ) {
	  now_y++;
	}
      }
      if( c == '^' ) {
	while( room[now_y][now_x] == c ) {
	  now_y--;
	}
      }
      printf("x : %d y : %d\n", now_x, now_y);
    }

    if( room[now_y][now_x] != '.' ) cout << "LOOP" << endl;
    else cout << now_x << " " << now_y << endl;
  }
}

C++: #include <iostream>

using namespace std;
/** Problem0104 : Magical Tiles **/
int main()
{
	char room[110][110];
	int w, h, x, y;
	
	while (cin >> h >> w, w != 0 && h != 0) {
		for (int y=0; y<h; y++) {
			for (int x=0; x<w; x++) {
				cin >> room[x][y];
			}
		}

		x=0; y=0;
		while (1) {
			if (room[x][y] == '>') {
				room[x][y] = 'L';
				x++;
			} else if (room[x][y] == '<') {
				room[x][y] = 'L';
				x--;
			} else if (room[x][y] == '^') {
				room[x][y] = 'L';
				y--;
			} else if (room[x][y] == 'v') {
				room[x][y] = 'L';
				y++;
			} else if (room[x][y] == 'L') {
				cout << "LOOP" << endl;
				break;
			} else if (room[x][y] == '.') {
				cout << x << " " << y << endl;
				break;
			}
		}
	}
}

C++: #include<iostream>
using namespace std;

int main(){
   int a, b, i, j;
   char map[102][102];
   
   while(1){
      cin >> a >> b;
      if(a+b==0) break;
      
      for(i=0; i< a; i++){
         for(j=0; j< b; j++){
            cin >> map[i][j];
         }
      }
      cout << endl;
      i=0,j=0;
      while(1){
         if(map[i][j]=='.'){
            cout << j << " " << i << endl;
            break;
         }else if(map[i][j]=='#'){
            cout << "loop" << endl;
            break;
         }else if(map[i][j]=='>'){
            map[i][j]='#';
            j++;
         }else if(map[i][j]=='<'){
            map[i][j]='#';
            j--;
         }else if(map[i][j]=='^'){
            map[i][j]='#';
            i--;
         }else if(map[i][j]=='v'){
            map[i][j]='#';
            i++;
         }
      }
   }
   return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define FOR(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
    stringstream ss;
    ss << t;
    ss >> u;
}

bool mark[101][101];
char tb[101][101];

void dfs(int x, int y, pair<int, int> &last){
	if(mark[y][x]) return;
	if(tb[y][x]=='.'){
		last.first  = x;
		last.second = y;
		return;
	}
	mark[y][x] = true;
	if(tb[y][x]=='^'){
		dfs(x, y-1, last);
	}else if(tb[y][x]=='>'){
		dfs(x+1, y, last);
	}else if(tb[y][x]=='v'){
		dfs(x, y+1, last);
	}else if(tb[y][x]=='<'){
		dfs(x-1, y, last);
	}
	return;
}

int main(){
	int w, h;
	while(cin >> h >> w && w|h){
		memset(mark, false, sizeof(mark));
		memset(tb, ' ', sizeof(tb));
		FOR(i, h){
			string tmp;
			cin >> tmp;
			FOR(j, w){
				tb[i][j] = tmp[j];
			}
		}

		pair<int, int> last(-1, -1);
		dfs(0, 0, last);

		if(last.first==-1&&last.second==-1){
			cout << "LOOP" << endl;
		}else{
			cout << last.first << " " << last.second << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

int main() {
	int W, H;
	while (cin >> W >> H && W+H!= 0) {
        char room[101][101];

        for (int w = 0; w != W; ++w) {
            cin >> room[w];
        }

        int x = 0, y = 0;
        bool loop = false;

        while (room[x][y] != '.') {
            if (room[x][y] == '>') {
                room[x][y] = 'x';
                y++;
            }
            else if (room[x][y] == '<') {
                room[x][y] = 'x';
                y--;
            }
            else if (room[x][y] == '^') {
                room[x][y] = 'x';
                x--;
            }
            else if (room[x][y] == 'v') {
                room[x][y] = 'x';
                x++;
            }
            else if (room[x][y] == 'x') {
                loop = true;
                break;
            }
        }

        if (loop) {
            cout << "LOOP" << endl;
        }
        else {
            cout << y << " " << x << endl;
        }
    }
    return 0;
}

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

#define REP(i, n) for ( int i = 0; i < n; i++ )

using namespace std;

void dump(vector<string> f, int x = -1, int y = -1) {
    REP(i, f.size()) {
        REP(j, f[i].size()) {
            if ( i == y && j == x )
                cout << "#";
            else
                cout << f[i][j];
        }
        cout << endl;
    }
}

/*
0:上
1:右
2:下
3:左
*/
int mx[] = {0, 1, 0, -1},
    my[] = {-1, 0, 1, 0};

vector< vector<int> > closed;

void go(vector<string> &f, int x, int y) {
    // dump(f, x, y);
    // cout << endl;

    while( f[y][x] != '.' ) {
        if ( closed[y][x] ) {
            cout << "LOOP" << endl;
            return;
        }
        closed[y][x] = 1;

        int mv = -1;

        switch(f[y][x]) {
            case '^':
                mv = 0;
                break;
            case '>':
                mv = 1;
                break;
            case 'v':
                mv = 2;
                break;
            case '<':
                mv = 3;
                break;
        }
        if ( mv != -1 ) {
            x += mx[mv];
            y += my[mv];
        }
        // dump(f, x, y); cout << endl;
    }
    cout << x << " " << y << endl;
}

int main() {
    int w, h;

    while( cin >> h >> w, w || h ) {
        vector<string> f(h);
        closed = vector< vector<int> >(h, vector<int>(w, 0));

        REP(i, h) {
            REP(j, w) {
                closed[i][j] = 0;
            }
        }

        REP(i, h) {
            cin >> f[i];
        }

        go(f, 0, 0);
    }

    return 0;
}