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 <iostream>
#include <string>
#include <vector>

typedef std::pair<int,int> coordinate;

int main()
{
	while (true) {
		int H, W;
		std::cin >> H >> W;
		if ( H==0 && W==0 ) break;
		
		std::string* board = new std::string[H];
		for (int i=0; i<H; i++) {
			std::cin >> board[i];
		}
		
		coordinate curr_pos = coordinate(0,0);
		int count = 0;
		while (true) {
			char mark = board[curr_pos.first][curr_pos.second];
			if (mark == '.') {
				std::cout << curr_pos.second << " " << curr_pos.first << std::endl;
				break;
			} else if (mark == '>') {
				curr_pos.second++;
			} else if (mark == '<') {
				curr_pos.second--;
			} else if (mark == '^') {
				curr_pos.first--;
			} else {
				curr_pos.first++;
			}
			count++;
			if (count > H * W) {
				std::cout << "LOOP" << std::endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int c[100][100],a,b,n;
char ch[100][100];
int check(int x,int y){
	c[x][y] = 1;
	switch (ch[x][y]) {
	case '>':
		if (c[x][y+1] == 1) return 1;
		n = check(x,y+1);
		break;
	case '<':
		if (c[x][y-1] == 1) return 1;
		n = check(x,y-1);
		break;
	case 'v':
		if (c[x+1][y] == 1) return 1;
		n = check(x+1,y);
		break;
	case '^':
		if (c[x-1][y] == 1) return 1;
		n = check(x-1,y);
		break;
	case '.':
		a = x;
		b = y;
		return 0;
		break;
	}
	return n;
}
int main(){
	int x,y,i,j;
	while(cin >> x >> y && (x != 0 && y != 0)){
		for(i=0;i<x;i++){
			cin >> ch[i];
		}
		if (check(0,0)) cout << "LOOP" << endl;
		else cout << b << " " << a << endl;
		for(i=0;i<100;i++){
			for(j=0;j<100;j++){
				c[i][j] = 0;
				ch[i][j] = '\0';
			}
		}
	}
	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;return;}
    v[y][x]=1;
    if(b[y][x]=='>')
        return dfs(y,x+1);
    if(b[y][x]=='v')
        return dfs(y+1,x);
    if(b[y][x]=='<')
        return dfs(y,x-1);
    if(b[y][x]=='^')
        return dfs(y-1,x);
    if(b[y][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 <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

more:
  int h, w; cin >> h >> w;
  cin.ignore();
  if (!h && !w) return 0;

  char f[h][w];
  rep (i, h) {
    rep (j, w) {
      char c = getchar();
      f[i][j] = c;
      if (! (c == '.' || c == 'v' || c == '^' || c == '<' || c == '>') ) {
        trace(cons(cons(i,j), c));
      }
      assert(c == '.' || c == 'v' || c == '^' || c == '<' || c == '>');
    }
    cin.ignore();
  }

  vector<pair<int, int>> history;

  int i = 0, j = 0;
  for (; f[i][j] != '.'; ) {
    switch (f[i][j]) {
      case '>': ++j; break;
      case '<': --j; break;
      case 'v': ++i; break;
      case '^': --i; break;
    }

    for (auto&x : history) {
      if (car(x) == i && cdr(x) == j) {
        cout << "LOOP" << endl;
        goto more;
      }
    }
    history.push_back(cons(i, j));
  }
  cout << (j) << ' ' << (i) << endl;

  goto more;
}

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

int main()
{
	bool f;
	int w,h,x,y;
	char t[128][128];

	while(cin >> h >> w, (h||w))
	{
		for(int i=0; i<h; i++)
		{
			cin >> t[i];
		}
	
		f=true;
		x=y=0;
		while(f)
		{
			switch(t[y][x])
			{
				case 0:
					cout << "LOOP" << endl;
					f=false;
					break;

				case '.':
					cout << x << " " << y << endl;
					f=false;
					break;

				case '>':
					t[y][x] = 0; x++;
					break;

				case '<':
					t[y][x] = 0; x--;
					break;

				case 'v':
					t[y][x] = 0; y++;
					break;

				case '^':
					t[y][x] = 0; y--;
					break;
			}
		}

	}
	return 0;
}

C++: #include<iostream>

std::pair<char,bool> data[101][101];

int main(){
	int h,w;
	while(std::cin>>h>>w){
		if(w==0&&h==0)break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				std::cin>>data[i][j].first;
				data[i][j].second=false;
			}
		}
		int x=0,y=0;
		while(true){
			if(data[y][x].second){
				std::cout<<"LOOP"<<std::endl;
				break;
			}else data[y][x].second=true;

			if(data[y][x].first=='^')y--;
			if(data[y][x].first=='>')x++;
			if(data[y][x].first=='v')y++;
			if(data[y][x].first=='<')x--;

			if(data[y][x].first=='.'){
				std::cout<<x<<" "<<y<<std::endl;
				break;
			}
		}
	}
	return 0;
}

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

#define REP(i, m, n) for(int i = m; i < static_cast<int>(n); ++i)
int main()
{
    int height, width;
    std::vector<std::string> tile = {">", "<", "^", "v", "."};
    
    while (std::cin >> height >> width) {
        if (height == 0 && width == 0) {
            break;
        }
        
        std::vector< std::vector<std::string> > table;
            
        REP(i, 0, height) {
        table.push_back( std::vector<std::string>() );
            
        REP(j, 0, width) {
            std::string data;
            std::cin >> std::setw(1) >> data;
            table[i].push_back(data);
        }
    }
            
        
        bool flag = true;

        while (flag){
            static int i = 0;
            static int j = 0;
            
            if (table[i][j] == tile[0]) {
                table[i][j] = ",";
                j++;
                continue;
            } else if (table[i][j] == tile[1]) {
                table[i][j] = ",";
                j--;
                continue;
            } else if (table[i][j] == tile[2]) {
                table[i][j] = ",";
                i--;
                continue;
            } else if (table[i][j] == tile[3]) {
                table[i][j] = ",";
                i++;
                continue;
            } else if (table[i][j] == ",") {
                flag = false;
                std::cout << "LOOP" << std::endl;
                i = j = 0;
            } else {
                flag = false;
                std::cout << i << " " << j << std::endl;
                i = j = 0;
            }
        }
    }
    
    return 0;
}