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 <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;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int h,w;
	while(cin>>h>>w,w||h){
		char a[h][w];
		for(int i=0;i<w;i++){
			for(int j=0;j<h;j++){
				cin>>a[i][j];
			}
		}
		bool flag=true;
		int i=0,j=0;
		while(flag){
			flag=true;
			if(a[i][j]=='v'){
				i++;
				a[i][j]='!';
			}
			else if(a[i][j]=='>'){
				j++;
				a[i][j]='!';
			}
			else if(a[i][j]=='<'){
				j--;
				a[i][j]='!';
			}
			else if(a[i][j]=='^'){
				i--;
				a[i][j]='!';
			}
			else if(a[i][j]=='.'){
				break;
			}
			else if(a[i][j]=='!'){
				flag=false;
			}
		}
		if(!flag){
			cout<<"LOOP"<<endl;
		}
		else{
			cout<<j<<' '<<i<<endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main() {
	int h, w; 
	while (cin >> h >> w) {
		if (!h && !w)return 0;
		char map[114][514];
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				cin >> map[i][j];
		int i = 0, j = 0;
		for (int p = 1; p <= 10000; p++) {
			if (map[i][j] == '.') {
				cout << j << ' ' << i << endl;
				continue;
			}
			else if (map[i][j] == '>') j++;
			else if (map[i][j] == '<') j--;
			else if (map[i][j] == '^') i--;
			else if (map[i][j] == 'v') i++;
		}
		cout << "LOOP\n";
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  char mas[100][101];
  int h,w,i,j,t=0,loop=0;
  while(1){
  cin >> h >> w;
  if(h==0 && w==0){
    break;
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin >> mas[i][j];
    }
  }
  i=0;
  j=0;
  while(1){
    t++;
    if(t>10201){
      loop++;
      break;
    }
    if(mas[i][j]=='<'){
      j--;
    }
    else if(mas[i][j]=='^'){
      i--;
    }
    else if(mas[i][j]=='v'){
      i++;
    }
    else if(mas[i][j]=='>'){
      j++;
    }
    if(mas[i][j]=='.'){
      break;
    }
  }
  if(loop!=0){
    cout << "LOOP" << endl;
  }
  else{
  cout << j << " " << i << endl;
  }
  }
  return (0);
}