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 <vector>
#include <string>
using namespace std;

int main()
{
  int W, H;
  while (cin >> W >> H) {
    if ((W | H) == 0)
      break;

    vector<string> tile(H);
    for (int i = 0; i < H; ++i)
      cin >> tile[i];

    int x = 0, y = 0;
    bool loop = false;
    vector<vector<int> > visited(H, vector<int>(W, 0));
    while (tile[y][x] != '.') {
      if (visited[y][x]) {
	loop = true;
	break;
      }

      visited[y][x] = 1;
      if (tile[y][x] == '>')
	++x;
      else if (tile[y][x] == '<')
	--x;
      else if (tile[y][x] == 'v')
	++y;
      else if (tile[y][x] == '^')
	--y;
    }

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

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;

int h,w;
vector<string> s;
vector<vi> v;
int x,y;
bool f;
char ope[4]={'>','<','^','v'};
int mx[4]={1,-1,0,0};
int my[4]={0,0,-1,1};

void calc(){
	if(v[y][x]){
		f=false;
		return;
	}
	v[y][x]=1;
	for(int i=0; i<4; i++){
		if(s[y][x]==ope[i]){
			x+=mx[i];
			y+=my[i];
			calc();
		}
	}
}


int main(){
	while(cin>>h>>w){
		if(h==0&&w==0)break;
		vector<string> t(h);
		vector<vi> u(h,vi(w,0));
		for(int i=0; i<h; i++)cin>>t[i];
		s=t;
		v=u;
		x=0;
		y=0;
		f=true;
		calc();
		if(f)cout<<x<<" "<<y<<endl;
		else cout<<"LOOP"<<endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int h, w;
  while(cin >> h >> w, h || w){
    char m[101][101];
    bool visited[101][101];
    bool loop = false;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> m[i][j];
        visited[i][j] = false;
      }
    }
    int ph = 0, pw = 0;
    while(m[ph][pw] != '.'){
      if(visited[ph][pw]) { loop = true; break; }
      visited[ph][pw] = true;
      int op = m[ph][pw];
      switch(op){
        case '>':
          pw += 1;
          break;
        case '<':
          pw -= 1;
          break;
        case 'v':
          ph += 1;
          break;
        case '^':
          ph -= 1;
          break;
        default:
          break;
      }
    }
    if(loop) cout << "LOOP" << endl;
    else cout << pw << " " << ph << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int H,W;
int fields[200][200];
bool dp[200][200];
int recoursion(int y,int x){
        if(dp[y][x])
                return false;
        dp[y][x]=true;
        if(fields[y][x]==0){
                H=y;W=x;
                return true;
        }
        else if(fields[y][x]==1)
                return recoursion(y-1,x);
        else if(fields[y][x]==2)
                return recoursion(y+1,x);
        else if(fields[y][x]==3)
                return recoursion(y,x-1);
        else if(fields[y][x]==4)
                return recoursion(y,x+1);
        else
                return false;
}
int main(){
        while(true){
                cin >> H >> W;
                if(H+W==0)
                        break;
                string str;
                for(int i=0 ; i<H ; i++ ){
                        cin >> str;
                        for(int l=0 ; l<W ; l++ ){
                                dp[i][l]=false;
                                if(str[l]=='.')
                                        fields[i][l]=0;
                                else if(str[l]=='^')
                                        fields[i][l]=1;
                                else if(str[l]=='v')
                                        fields[i][l]=2;
                                else if(str[l]=='<')
                                        fields[i][l]=3;
                                else if(str[l]=='>')
                                        fields[i][l]=4;
                        }
                }
                if(recoursion(0,0))
                        cout<<W<<" "<<H<<endl;
                else
                        cout<<"LOOP"<<endl;
        }
        return 0;
}

C++: #define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 101
#define HO 6
int main(void)
{
	int H, W;
	while (scanf_s("%d %d", &H,&W) != EOF) {
		if (H == 0 && W == 0) break;
		char tile[MAX][MAX];
		int  h = 0, w = 0;
		bool tile_b[MAX][MAX] = { 0 };
		for (int i = 0; i < H; ++i) {
			scanf_s("%s", tile[i], MAX);
		}
		h = 0; w = 0;
		while (1) {
			if (tile[h][w] == '.') { 
				printf("%d %d\n",w,h); break; 
			}
			if (tile_b[h][w] == true) {
				printf("LOOP\n"); break;
			}
			tile_b[h][w] = true;
			switch (tile[h][w]) {
			case '>': ++w; break;
			case '<': --w; break;
			case 'v': ++h; break;
			case '^': --h; break;
			}
		}
		
	}
}