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;
#define UUI long long int
UUI x,y,n,m;
char tile[120][120],a;
int main(){
    while(1){
            cin >> n >> m;
            if(n==0&&m==0)break;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a;
            tile[i][j]=a;
        }
    }
    x=0;
    y=0;
    for(int i=0;i<11000;i++){
            if(tile[y][x]==0){
                    cout << "LOOP" << endl;
                    break;
            }
    if(tile[y][x]=='>'){
        tile[y][x]=0;
        x=x+1;
    }else if(tile[y][x]=='<'){
        tile[y][x]=0;
        x=x-1;
    }else if(tile[y][x]=='^'){
        tile[y][x]=0;
        y=y-1;
    }else if(tile[y][x]=='v'){
        tile[y][x]=0;
        y=y+1;
    }else if(tile[y][x]=='.'){
            cout << y <<" "<< x << endl;
        break;
    }
    }
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            tile[i][j]=0;
        }
    }
    }
return 0;
}

C++: //include----------------------------------------------------------------------------------------------------------------------
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cctype>
#include <vector>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <map>
#include <algorithm>
#include <memory>
#include <sstream>
#include <functional>
#include <iostream>
#include <fstream>
#include <set>

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, s, n) for(int i = s; i < n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define FOREACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;

//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//global-----------------------------------------------------------------------------------------------------------------------
char str[1000][1000];
bool test[1000][1000];
int ans_x, ans_y;
//function---------------------------------------------------------------------------------------------------------------------
bool solve(int x, int y){
	if (str[y][x] == '.'){
		ans_y = y + 1;
		ans_x = x + 1;
		return true;
	}
	if (test[y][x]){
		ans_x = INF;
		ans_y = INF;
		return true;
	}
	test[y][x] = true;
	if (str[y][x] == '>'){
		if (solve(x + 1, y))
			return true;
	}
	if (str[y][x] == '<'){
		if (solve(x - 1, y))
			return true;
	}
	if (str[y][x] == '^'){
		if (solve(x, y + 1))
			return true;
	}
	if (str[y][x] == 'v'){
		if (solve(x, y - 1))
			return true;
	}
}

int main(){
	char str[1000][1000];
	int a, b;
	while(true){
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0)
			return 0;
		rep(i, a)
			scanf("%s", str[i]);
		rep(i, a)
			rep(j, b)
			test[i][j] = false;
		if (solve(0, 0)){
			if (ans_y == INF && ans_x == INF)
				printf("LOOP\n");
			else
				printf("%d %d", ans_y, ans_x);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    int w,h;
    while(cin>>h>>w,h) 
    {
        string f[h];
        for(int i = 0; i < h; ++i)
        {
            cin>>f[i];
        }
 
        bool used[h][w];
        memset(used,0,sizeof(used));
 
        int x=0,y=0;
        while(1) 
        {
            if(used[y][x])
            {
                cout<<"LOOP"<<endl;
                break;
            }
            if(f[y][x]=='.')
            {
                cout<<x<<" "<<y<<endl;
                break;
            }
            used[y][x]=true;
 
            if(f[y][x]=='>') x+=1;
            if(f[y][x]=='<') x-=1;
            if(f[y][x]=='^') y-=1;
            if(f[y][x]=='v') y+=1;
        }
    }
  return 0;
}

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

int m,n,w,h;
char b[102][102];
bool v[102][102];

void dfs(int y,int x){
    if(v[y][x])
        cout<<"LOOP"<<endl;
    v[y][x]=1;
    if(b[y][x]=='>')
        dfs(y,x+1);
    if(b[y][x]=='v')
        dfs(y+1,x);
    if(b[y][x]=='<')
        dfs(y,x-1);
    if(b[y][x]=='^')
        dfs(y-1,x);
    cout<<x<<" "<<y<<endl;
}

int main(){
    while(cin>>h>>w,w||h){
        for(int i=0;i<h;i++)
            cin>>b[i];
        memset(v,0,sizeof(v));
        dfs(0,0);
    }
}

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

int main(){
	int w,h;
	while(cin>>w>>h )
	{
		if(h==0 || w==0)break;
		char mass[102][102];
		bool key[102][102];

		for( int i=0; i<102; i++) {
			for( int j=0; j<102; j++){
				key[i][j]=false;
			}
		}

		for( int i=0; i<h; i++) {
			for( int j=0; j<w; j++){
				cin>>mass[i][j];
				key[i][j]=false;
			}
		}
		w=0,h=0;
		while(1)
		{
			key[h][w]=true;
			if( mass[h][w] == '>' ) w++;
			else if( mass[h][w] == '<' ) w--;
			else if( mass[h][w] == '^' ) h--;
			else if( mass[h][w] == 'v' ) h++;
			else {
				cout<<w<<" "<<h<<endl;
				break;
			}
			
			if(key[h][w]) {
				puts("LOOP");
				break;
			}
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(){
  while(1){
    int h, w;
    scanf("%d %d", &h, &w);
    if(h==0 && w==0)
      break;
    else{
      char s[100][100];
      int i;
      for(i=0;i<h;i++){	
	scanf("%s", s[i]);
      }
      int x=0;
      int y=0;
      int xx[10000]={};
      int yy[10000]={};
      int j=0;
      while(1){
	xx[j]=x;
	yy[j]=y;
	j++;
	if(s[x][y] == '>')
	  y++;
	if(s[x][y] == '<')
	  y--;
	if(s[x][y] == '^')
	  x--;
	if(s[x][y] == 'v')
	  x++;	
	if(s[x][y] == '.')
	  {printf("%d %d\n", y, x);break;}
	
	int k;
	int flag=0;
	for(k=0;k<10000;k++){
	  if(xx[k]==x && yy[k]==y){flag++;}
	}
	if(flag!=0)
	  {printf("LOOP\n");break;}
      }
    }
  }
  return 0;
}