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 <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int H, W; cin >> H >> W;
    do {
        char state[H][W];
        bool used[H][W] = {true};
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> state[i][j];
                used[i][j] = true;
            }
        }

        int i = 0, j = 0;
        while (state[i][j] != '.' && used[i][j] == true) {
            used[i][j] = false;
            if (state[i][j] == '>') j++;
            else if (state[i][j] == '<') j--;
            else if (state[i][j] == '^') i--;
            else i++;

        }
        if (used[i][j] == false) cout << "LOOP" << endl;
        else cout << j << " " << i << endl;
        cin >> H >> W;
    } while (H != 0 && W != 0);
    return 0;

}

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

char map[11][11] ;
char d[] = { '>' , 'v' , '<' , '^' } ;
int dx[] = { 1,0,-1,0 } ;
int dy[] = { 0,1,0,-1 } ;

void move( int y , int x ){
	if( map[y][x] == '.' ) cout << x << ' ' << y << endl ;
	else if( map[y][x] == '0' ) cout << "LOOP" << endl ;
	else {
		for( int j=0 ; j<4 ; j++ ){
			if( map[y][x] == d[j] ){
				map[y][x] = '0' ;
				move( y+dy[j] , x+dx[j] ) ;
			}
		}
	}
}

int main(){
	
	int h , w ;
	
	while( cin >> h >> w , h ){
		for( int i=0 ; i<h ; i++ ){
			for( int j=0 ; j<w ; j++ ){
				cin >> map[i][j] ;
			}
		}
		
		move(0,0) ;
	}
	
return 0 ;
}

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

int w, h;
char map[102][102];
bool closed[102][102];
void rec(int x, int y){
  if(closed[y][x]){
    cout << "LOOP" << endl;
    return;
  }
  closed[y][x] = true;
  if(map[y][x] == '>')rec(x+1,y);
  else if(map[y][x] == 'v')rec(x, y+1);
  else if(map[y][x] == '<')rec(x-1,y);
  else if(map[y][x] == '^')rec(x,y-1);
  else {
    cout << x << " " << y << endl;
  }
}
void solve(){
  rec(0,0);
}
int main(){
  while(cin >> h >> w, w||h){
    memset(closed, 0, sizeof(closed));
    for(int i = 0; i < h; i++)cin >> map[i];
    solve();
  }
  return 0;
}

C++: 
#include <iostream>
#include <istream>
#include <ostream>

class Tiles {
	char **dir;
	bool **visited;
	int pos_x, pos_y;
	int h, w;
public:
	Tiles(std::istream& is) {
		is >> h >> w;
		if (h == 0 && w == 0) {
			return;
		}
		dir = new char*[h];
		visited = new bool*[h];
		for (int i = 0; i < w; i++) {
			dir[i] = new char[w];
			visited[i] = new bool[w];
		}
		pos_x = pos_y = 0;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				std::cin >> dir[i][j];
			}
		}
	}

	void solve() {
		if (visited[pos_y][pos_x]) {
			std::cout << "LOOP" << std::endl;
			return;
		}
		if (dir[pos_y][pos_x] == '.') {
			std::cout << pos_x << ' ' << pos_y << std::endl;
		} else {
			visited[pos_y][pos_x] = true;
			switch (dir[pos_y][pos_x]) {
			case '>':
				pos_x++;
				break;
			case '<':
				pos_x--;
				break;
			case 'v':
				pos_y++;
				break;
			case '^':
				pos_y--;
				break;
			}
			solve();
		}
	}

	bool is_empty() { return (h == 0 && w == 0); }
};

int main()
{
	Tiles *t;
	while (true) {
		t = new Tiles(std::cin);
		if (t->is_empty())
			break;
		t->solve();
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000010;
const int MAX=100001;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int h,w;
char c[110][110];
bool visited[110][110];
void dfs(int x,int y){
	if(visited[y][x]){
		cout<<"LOOP"<<endl;
		return;
	}
	visited[y][x]=true;
	if(c[y][x]=='>'){
		dfs(x+1,y);
		return;
	}
	if(c[y][x]=='<'){
		dfs(x-1,y);
		return;
	}
	if(c[y][x]=='v'){
		dfs(x,y+1);
		return;
	}
	if(c[y][x]=='^'){
		dfs(x,y-1);
		return;
	}
	cout<<x<<" "<<y<<endl;
	return;
}
int main(){
   	while(cin>>h>>w,h+w){
		for(int i=0;i<h;i++){
			cin>>c[i];
			for(int j=0;j<w;j++){
				visited[i][j]=false;
			}
		}
		dfs(0,0);
	}
    return 0;
}

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

vector<string> mp;
int a[100][100];

bool solve(int y, int x){
  if(a[y][x]==1)return false;//すでに通った
  a[y][x]=1;

  if(mp[y][x]=='.'){cout<<x<<' '<<y<<endl; return true;}
  else if(mp[y][x]=='>')x++;
  else if(mp[y][x]=='v')y++;
  else if(mp[y][x]=='<')x--;
  else if(mp[y][x]=='^')y--;

  if(solve(y, x))return true;
  else return false;
}

int main(){
  int h, w;
  while(true){
    cin>>h>>w;
    if(h==0 && w==0)break;
    mp.clear();
    memset(a, 0, sizeof(a));
    for(int i=0; i<h; i++){
      string s;
      cin>>s;
      mp.push_back(s);
    }
    if(!solve(0, 0))cout<<"LOOP"<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	while(true){
		int W, H;
		cin >> H >> W;
		if(H == 0 || W == 0){ break; }
		vector<string> field(H);
		for(int i = 0; i < H; ++i){ cin >> field[i]; }
		int x = 0, y = 0;
		while(field[y][x] != '.' && field[y][x] != ' '){
			int px = x, py = y;
			switch(field[y][x]){
				case '>': ++x; break;
				case '<': --x; break;
				case 'v': ++y; break;
				case '^': --y; break;
			}
			field[py][px] = ' ';
		}
		if(field[y][x] == ' '){
			cout << "LOOP" << endl;
		}else{
			cout << x << " " << y << endl;
		}
	}
	return 0;
}

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

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

using namespace std;

int main()
{
	int n,m;
	string f[101];
	while(true)
	{
		cin >> n >> m;
		if(n == 0 && m == 0) break;

		rep(i,n)
		{
			cin >> f[i];
		}

		int i = 0, j = 0;
		int memo[101][101];
		memset(memo,0,sizeof(memo));
		while(f[i][j] != '.' && memo[i][j] == 0)
		{
			memo[i][j]++;

			if(f[i][j] == '>')
			{
				j++;
			}
			else if(f[i][j] == '<')
			{
				j--;
			}
			else if(f[i][j] == 'v')
			{
				i++;
			}
			else if(f[i][j] == '^')
			{
				i--;
			}
		}

		if(memo[i][j] == 0)
		{
			cout << j << " "  << i << endl;
		}
		else
		{
			cout << "LOOP" << endl;
		}


	}
	return 0;
}