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 <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <set>
using namespace std;
bool calc(vector<vector<char> >, int y, int x);
int resultx;
int resulty;
set<string> passed;

int main() {
  while(true) {
  int width, height;
  cin >> width >> height;
  if(width == 0 && height == 0) break;
  vector<vector<char> > field(width, vector<char>(height));
  for(int w = 0; w < width; ++w) {
    for(int h = 0; h < height; ++h) {
      cin >> field[w][h];
    }
  }
  if(calc(field, 0, 0)) cout << resulty << " " << resultx << endl;
  }
  return 0;
}

bool calc(vector<vector<char> > field, int y, int x) {
  stringstream ss;
  ss << y << ',' << x;
  // cout << ss.str() << endl;
  if(passed.find(ss.str()) != passed.end()) {
    cout << "LOOP" << endl;
    return false;
  }
  passed.insert(ss.str());
  switch(field[x][y]) {
    case '>':
      calc(field, y + 1, x);
      break;
    case '<':
      calc(field, y - 1, x);
      break;
    case '^':
      calc(field, y, x - 1);
      break;
    case 'v':
      calc(field, y, x + 1);
      break;
    case '.':
      resultx = x;
      resulty = y;
      return true;
  }
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
 
int main(){
    while(1){
        int h, w;
        char f[102][102];
         
        scanf(" %d %d", &h, &w);
        if(h==0) break;
         
        for(int i=0; i<h; ++i)
        for(int j=0; j<w; ++j)
        scanf(" %c", &f[i][j]);
         
        int x=0, y=0;
        bool loop=false;
        while(!loop && f[y][x]!='.'){
            if(f[y][x]=='a') loop=true;
            else{
                int tx=x, ty=y;
                 
                if(f[y][x]=='>') ++x;
                else if(f[y][x]=='<') --x;
                else if(f[y][x]=='^') --y;
                else if(f[y][x]=='v') ++y;          
                 
                f[ty][tx]='a';
            }
        } 
        if(loop) printf("LOOP\n");
        else printf("%d %d\n", x, y);
    }
}

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

using namespace std;

int H, W;
int ansx, ansy;
int tile[100][100];

void move(int x, int y) {
	int here = tile[y][x];
	tile[y][x] = -1;

	if (here) {
		if (here == -1) {
			ansx = -1;
			ansy = -1;
		}
		else if (here == 1)		move(x+1, y);
		else if (here == 2)	move(x-1, y);
		else if (here == 3) move(x, y-1);
		else				move(x, y+1);
	}
	else {
		ansx = x, ansy = y;
	}

	return;
}

int main() {
	string str;

	while (cin >> H >> W) {
		if (H == 0 && W == 0) break;

		for (int i = 0; i < H; i++) {
			cin >> str;
			
			for (int j = 0; j < W; j++) {
				tile[i][j] = (str[j] == '.') ? 0 : (str[j] == '>') ? 1 : (str[j] == '<') ? 2 : (str[j] == '^') ? 3 : 4;
			}
		}

		move(0, 0);

		if (ansx == -1 && ansy == -1)
			cout << "LOOP" << endl;
		else
			cout << ansx << ' ' << ansy << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

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

using namespace std;

void dump(vector<string> f, int x = -1, int y = -1) {
    REP(i, f.size()) {
        REP(j, f[i].size()) {
            if ( i == y && j == x )
                cout << "#";
            else
                cout << f[i][j];
        }
        cout << endl;
    }
}

/*
0:上
1:右
2:下
3:左
*/
int mx[] = {0, 1, 0, -1},
    my[] = {-1, 0, 1, 0};

vector< vector<int> > closed;

void go(vector<string> &f, int x, int y) {
    // dump(f, x, y);
    // cout << endl;

    while( f[y][x] != '.' ) {
        if ( closed[y][x] ) {
            cout << "LOOP" << endl;
            return;
        }
        closed[y][x] = 1;

        int mv = -1;

        switch(f[y][x]) {
            case '^':
                mv = 0;
                break;
            case '>':
                mv = 1;
                break;
            case 'v':
                mv = 2;
                break;
            case '<':
                mv = 3;
                break;
        }
        if ( mv != -1 ) {
            x += mx[mv];
            y += my[mv];
        }
        // dump(f, x, y); cout << endl;
    }
    cout << x << " " << y << endl;
}

int main() {
    int w, h;

    while( cin >> h >> w, w || h ) {
        vector<string> f(h);
        closed = vector< vector<int> >(h, vector<int>(w, 0));

        REP(i, h) {
            REP(j, w) {
                closed[i][j] = 0;
            }
        }

        REP(i, h) {
            cin >> f[i];
        }

        go(f, 0, 0);
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
string s[100];
bool used[100][100];
int h,w;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
main()
{
    while(cin>>h>>w,h)
    {
        for(int i=0;i<h;i++)
        {
            cin>>s[i];
            for(int j=0;j<w;j++)used[i][j]=0;
        }
        int x=0,y=0,f=0;
        while(!used[x][y])
        {
            used[x][y]=1;
            if(s[x][y]=='.')
            {
                f=1;
                cout<<y<<" "<<x<<endl;
                break;
            }
            int r=s[x][y]=='>'?0:s[x][y]=='<'?2:s[x][y]=='v'?1:3;
            x+=dx[r],y+=dy[r];
        }
        if(!f)cout<<"LOOP"<<endl;
    }
}

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

int main(){
	int w,h;
	while(cin>>w>>h )
	{
		if(h==0 || w==0)break;
		char mass[102][102];
		bool key[102][102];

		for( int i=0; i<h; i++) {
			for( int j=0; j<w; j++){
				cin>>mass[i][j];
				key[i][j]=false;
			}
		}
		w=0,h=0;
		while(1)
		{
			key[h][w]=true;
			if( mass[h][w] == '>' ) w++;
			else if( mass[h][w] == '<' ) w--;
			else if( mass[h][w] == '^' ) h--;
			else if( mass[h][w] == 'v' ) h++;
			else {
				cout<<w<<" "<<h<<endl;
				break;
			}
			
			if(key[h][w]) {
				puts("LOOP");
				break;
			}
		}
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int H,W,x,y,flag;
char tile[100][101];

int main(){
	while(cin>>H>>W){
		if(H+W==0)return 0;
		for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>tile[i][j];
		x=0;y=0;flag=0;
		for(int i=0;i<10000;i++){
			if(tile[y][x]=='.'){
				cout<<x<<" "<<y<<endl;
				flag=1;
				break;
			}
			if(tile[y][x]=='>')x++;
			if(tile[y][x]=='<')x--;
			if(tile[y][x]=='^')y--;
			if(tile[y][x]=='v')y++;
		}
		if(flag==0)cout<<"LOOP"<<endl;
	}
}