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

int H, W;

void solve() {
	string b[100];
	for (int i = 0; i < H; i++) {
		cin >> b[i];
	}

	bool visited[100][100] = {0};
	int x = 0, y = 0;

	while (b[y][x] != '.') {
		if (visited[y][x]) {
			cout << "LOOP" << endl;
			return;
		}
		visited[y][x] = true;
		if (b[y][x] == '^') y--;
		if (b[y][x] == 'v') y++;
		if (b[y][x] == '<') x--;
		if (b[y][x] == '>') x++;
	}

	cout << x << " " << y << endl;
}

int main() {
	while (cin >> H >> W , H) {
		solve();
	}
}

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];
         }
      }
      i=0;j=0;
      while(1){
         if(map[i][j]=="."){
            cout << i << " " << j << 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 <cstring>
using namespace std;

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

char t[]={'<','^','>','v'};

char f[101][101];
bool v[100][100];
int X,Y;

bool dfs()
{
	if(v[X][Y]) return false;
	v[X][Y]=1;
	if(f[X][Y]=='.') return true;
	
	for(int i=0; i<4; i++)
	{
		if(t[i]==f[X][Y]) 
		{
			X+=dx[i];
			Y+=dy[i];
		}
	}
	return dfs();
}

int main()
{
	int H,W;
	while(cin >> H >> W, (H||W))
	{
		memset(v,0,sizeof(v));
		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
			cin >> f[j][i];
			
		X=0; Y=0;
		
		bool f=dfs();
		if(f) cout << X << " " << Y << endl;
		else cout << "LOOP" << endl;
		
	}
}

C++: #include <cstdio>
#include <utility>
#include <vector>

using namespace std;

enum class Direction { North, East, South, West, Stop, Invalid };

Direction ToDirection(char sym) {
  switch (sym) {
    case '^':
      return Direction::North;
    case '>':
      return Direction::East;
    case 'v':
      return Direction::South;
    case '<':
      return Direction::West;
    case '.':
      return Direction::Stop;
    default:
      return Direction::Invalid;
  }
}

int main() {
  while (true) {
    int h, w;
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0) { break; }

    vector<vector<bool>> visited(h);
    vector<vector<Direction>> map(h);
    for (int y = 0; y < h; ++y) {
      visited[y] = std::move(vector<bool>(w));
      map[y] = std::move(vector<Direction>(w));
      for (int x = 0; x < w; ++x) {
     REDO:
        Direction d = ToDirection(getchar());
        if (d == Direction::Invalid) { goto REDO; }
        map[y][x] = d;
      }
      getchar(); // Drops newline
    }
    typedef pair<int, int> Position;
    Position position(0, 0);
    Direction next_direction = map[0][0];
    while (next_direction != Direction::Stop) {
      if (visited[position.first][position.second]) {
        puts("LOOP");
        goto NEXT_DATA;
      }
      visited[position.first][position.second] = true;
      switch (next_direction) {
        case Direction::North:
          position.first -= 1;
          break;
        case Direction::East:
          position.second += 1;
          break;
        case Direction::South:
          position.first += 1;
          break;
        case Direction::West:
          position.second -= 1;
          break;
        case Direction::Stop:
          puts("not reached");
          break;
      }
      next_direction = map[position.first][position.second];
    }
    printf("%d %d\n", position.second, position.first);
 NEXT_DATA:
    ;
  }

  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>

using namespace std;

int main()
{
	int w,h;
	char room[101][101];
	while(cin>>h>>w,h){
		for(int i=0;i<h;i++)	cin>>room[i];
		int x=0,y=0,cnt=0;
		while(1){
			if     (room[y][x]=='>')	x++;
			else if(room[y][x]=='<')	x--;
			else if(room[y][x]=='^')	y--;
			else if(room[y][x]=='v')	y++;
			else{
				cout<<x<<" "<<y<<endl;
				break;
			}

			if(cnt>w*h){
				cout<<"LOOP"<<endl;
				break;
			}
			cnt++;
		}
	}

	return 0;
}

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

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

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

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

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

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

    return 0;
}