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 <iostream>
using namespace std;

char map[100][100];

int main(){
    int h, w;

    while(cin >> h >> w, h != 0 || w != 0){
        int x, y;
        bool loop = false;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                cin >> map[j][i];
            }
        }
        x = 0;
        y = 0;
        for(int i=1; i<=10000; i++){
            if(map[x][y] == '!'){
                loop = true;
                break;
            }
            if(map[x][y] == '.'){
                break;
            }
            if(map[x][y] == '>'){
                map[x][y] = '!';
                x++;
            }
            else if(map[x][y] == '<'){
                map[x][y] = '!';
                x--;
            }
            else if(map[x][y] == 'v'){
                map[x][y] = '!';
                y++;
            }
            else if(map[x][y] == '^'){
                map[x][y] = '!';
                y--;
            }
        }
        if(loop) cout << "LOOP" << endl;
        else cout << x << " " << y << endl;
    }
    return 0;
}

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

#define RIGHT '>'
#define LEFT '<'
#define TOP '^'
#define UNDER 'v'
#define LOOP 'l'
#define END '.'
#define MAX 101

int main(){
    char mp[MAX][MAX];
    int n,m;
    
    while(true){
        cin >> n >> m;
        if(!n&&!m) break;
        
        for(int i = 0 ; i < n ; i++)
            for(int j = 0 ; j < m ; j++)
                cin >> mp[i][j];
        
        int x = 0,y = 0;
        while(true){
            if(mp[x][y]==END){
                cout << y << ' ' << x << endl;
                break;
            }
            if(mp[x][y]==LOOP){
                cout << "LOOP" << endl;
                break;
            }
            
            if(mp[x][y]==RIGHT){
                mp[x][y] = LOOP;
                y++;
            }
            else if(mp[x][y]==LEFT){
                mp[x][y] = LOOP;
                y--;
            }
            else if(mp[x][y]==TOP){
                mp[x][y] = LOOP;
                x--;
            }
            else{
                mp[x][y] = LOOP;
                x++;
            }
        }
    }
    
    return 0;
}

C++: #include <stdio.h>

int main() {
  int i, j, w, h;
  char c, m[101][101];
  bool b[101][101], loop;

  while (1) {
    scanf("%d %d", &w, &h);
    if (!w && !h) break;
    for (i=0; i<h; i++) {
      for (j=0; j<w; j++) {
        do {
        scanf("%c", &c);
        m[i][j] = c;
        } while (c=='\n'||c=='\r');
      }
    }
    for (i=0; i<h; i++) {
      for (j=0; j<w; j++) {
        b[i][j] = false;
      }
    }
    i = j = 0;
    loop = false;
    while (1) {
      if (b[i][j]) {
        loop = true;
        break;
      }
      b[i][j] = true;
      c = m[i][j];
      if (c == '>') ++j;
      else if (c == '<') --j;
      else if (c == '^') --i;
      else if (c == 'v') ++i;
      else break;
    }
    if (!loop) {
      printf("%d %d\n", j, i);
    } else {
      printf("LOOP\n");
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int h,w;
    while(cin>>h>>w, h+w){
        vvc v(h,vc(w));
        rep(i,h)rep(j,w)cin>>v[i][j];
        pii now=pii(0,0);
        int cnt=0; bool flag=true;
        for(;cnt<=10000000;cnt++){
            if(v[now.first][now.second]=='>')now=pii(now.first,now.second+1);
            else if(v[now.first][now.second]=='<')now=pii(now.first,now.second-1);
            else if(v[now.first][now.second]=='^')now=pii(now.first-1,now.second);
            else if(v[now.first][now.second]=='v')now=pii(now.first+1,now.second);
            else break;
            if(cnt==10000000) {flag=false; puts("LOOP");}
        }
        if(flag)cout<<now.second<<" "<<now.first<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
int GCD(int a, int b){
    if(b==0) return a;
    return GCD(b, a%b);
}
int H, W;
int main() {
    while(cin>>H>>W, H||W){
        vector<string> field;
        bool check[H][W];
        for(int i=0; i<H; ++i){
            for(int j=0; j<W; ++j){
                check[i][j]=false;
            }
        }
        cin.ignore();
        for(int i=0; i<H; ++i){
            string str; getline(cin, str);
            field.push_back(str);
        }
        int x=0, y=0;
        while(1){
            check[y][x]=true;
            
            if(field[y][x]=='.'){
                cout << x << " " << y << endl;
                break;
            }
            if(field[y][x]=='>') {
                if(check[y][x+1]) {
                    cout << "LOOP" << endl;
                    break;
                }
                x++; continue;
            }
            if(field[y][x]=='v'){
                if(check[y+1][x]) {
                    cout << "LOOP" << endl;
                    break;
                }
                y++; continue;
            }
            if(field[y][x]=='^'){
                if(check[y-1][x]) {
                    cout << "LOOP" << endl;
                    break;
                }
                y--; continue;
            }
            if(field[y][x]=='<'){
                if(check[y][x-1]) {
                    cout << "LOOP" << endl;
                    break;
                }
                x--; continue;
            }
        }
        
    }
	return 0;
}