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 <bits/stdc++.h>

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

char field[101][101];
bool isLeave[101][101];

char getNextPosTileAndNextPos(int x, int y, int* nextX, int* nextY)
{
	char result = '.';

	switch( field[y][x] )
	{
		case '>':
			result = field[y][x + 1];
			*nextX = x + 1;
			*nextY = y;
			break;
		case '<':
			result = field[y][x - 1];
			*nextX = x - 1;
			*nextY = y;
			break;
		case '^':
			result = field[y - 1][x];
			*nextX = x;
			*nextY = y - 1;
			break;
		case 'v':
			result = field[y + 1][x];
			*nextX = x;
			*nextY = y + 1;
			break;
		case '.':
			break;
	}
	return result;
}

int main()
{
	int w;
	int h;
	int x;
	int y;

	while( true )
	{
		scanf("%d%d", &h, &w);
		if( w == 0 && h == 0 )break;
		x = 0;
		y = 0;
		loop(i, 0, h)
		{
			scanf("%s", field[i]);
		}
		loop(i, 0, h)
		{
			loop(j, 0, w)
			{
				isLeave[i][j] = false;
			}
		}
		
		do
		{
			if( isLeave[y][x] )
			{
				printf("LOOP\n");
				break;
			}
			isLeave[y][x] = true;
		}
		while( getNextPosTileAndNextPos( x, y, &x, &y ) != '.' );
		if( field[y][x] == '.' )
		{
			printf("%d %d\n", x, y);
		}
	}
	return (0);
}

C++: #include <iostream>
#include <istream>
#include <ostream>
#include <cstdlib>

class Tiles {
	char **dir;
	bool **visited;
	int pos_x, pos_y;
public:
	Tiles(std::istream& is) {
		int h, w;
		is >> h >> w;
		if (h == 0 && w == 0) {
			exit(0);
		}
		dir = new char*[h];
		visited = new bool*[h];
		for (int i = 0; i < w; i++) {
			dir[i] = new char[w];
			visited[i] = new bool[w];
		}
		pos_x = pos_y = 0;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				std::cin >> dir[i][j];
			}
		}
	}

	void solve() {
		if (visited[pos_y][pos_x]) {
			std::cout << "LOOP" << std::endl;
			return;
		}
		if (dir[pos_y][pos_x] == '.') {
			std::cout << pos_x << ' ' << pos_y << std::endl;
		} else {
			visited[pos_y][pos_x] = true;
			switch (dir[pos_y][pos_x]) {
			case '>':
				pos_x++;
				break;
			case '<':
				pos_x--;
				break;
			case 'v':
				pos_y++;
				break;
			case '^':
				pos_y--;
				break;
			}
			solve();
		}
	}
};

int main()
{
	Tiles *t;
	while (true) {
		t = new Tiles(std::cin);
		t->solve();
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int H,W,x,y;
  while(cin>>H>>W){
    if(H==0&&W==0) break;
    char space[H][W],c;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> space[j][i];
      }
    }
    x = y = 0;
    while(1){
      c = space[x][y];
      space[x][y] = '0';
      if(c=='>') x++;
      else if(c=='<') x--;
      else if(c=='v') y++;
      else if(c=='^') y--;
      else if(c=='.'){
	cout << x << ' ' << y << endl;
	break;
      }
      else if(c=='0'){
	cout << "LOOP" << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define W_MAX 100
#define H_MAX 100
char map[H_MAX+1][W_MAX+1];
char gx,gy;
int solve(int posX,int posY)
{
	if(map[posY][posX]=='x')
		return 0;
	char c=map[posY][posX];
	map[posY][posX]='x';
	if(c=='^')
		return solve(posX,posY-1);
	else if(c=='v')
		return solve(posX,posY+1);
	else if(c=='>')
		return solve(posX+1,posY);
	else if(c=='<')
		return solve(posX-1,posY);
	else if(c=='.'){
		gx=posX;gy=posY;
		return 1;
	}
	return 1;
}
int main(void)
{
	int w,h,k;
	char str[101];
	while(true){
		scanf("%d%d",&h,&w);
		if(h==0||w==0)break;
		for(k=0;k<h;k++)
		{
			scanf("%s",&str);
			strcpy(map[k],str);
		}
		if(solve(0,0)==1)printf("%d %d\n",gx,gy);
		else printf("LOOP\n");
	}
}

C++: //============================================================================
// Name        : 0104.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <cstdio>
#include <string>
#include <utility>
using namespace std;

const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
char tbl[100][101];

pair<int,int> rec(int y,int x){
	if(tbl[y][x] == '#'){
		return make_pair(-1,-1);
	}else if(tbl[y][x] == '.'){
		return make_pair(y,x);
	}
	if(tbl[y][x] == '>'){
		tbl[y][x] = '#';
		return rec(y,x + 1);
	}else if(tbl[y][x] == 'v'){
		tbl[y][x] = '#';
		return rec(y + 1,x);
	}else if(tbl[y][x] == '<'){
		tbl[y][x] = '#';
		return rec(y, x - 1);
	}else{
		tbl[y][x] = '#';
		return rec(y - 1,x);
	}
}

int main() {
	int h, w;
	pair<int,int> ans;
	while(true){
		scanf("%d%d",&h,&w);
		if(h == 0 && w == 0){
			break;
		}
		getchar();
		for(int i = 0;i < h;i++){
			scanf("%s",tbl[i]);
		}
		ans = rec(0,0);
		if(ans.first == -1 && ans.second == -1){
			printf("LOOP\n");
		}else{
			printf("%d %d\n",ans.second,ans.first);
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	char d[101][101];
	int w,h,k,x,y;
	while(cin >> w >> h) {
		if (w+h==0) break;
		for (y=0;y<h;y++) cin >> d[y];
		x=0; y=0; k=0;
		while(true) {
			if (d[y][x]=='.') { cout << x << " " << y << endl; break;}
			switch(d[y][x]) {
				case '<':  x--; break;
				case '>':  x++; break;
				case '^':  y--; break;
				case 'v':  y++; break;
			}
			k++;
			if (k>w*h) {cout << "LOOP" << endl; break;}
		}
	}
    return 0;
	}

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

int z(char c) {
  if(c=='^') return 1;
  if(c=='<') return 2;
  if(c=='v') return 3;
  if(c=='>') return 4;
  return 0;
}

int main() {
  int n,m;
  int dx[5]={0,-1,0,1,0},dy[5]={0,0,-1,0,1};
  while(cin >> n >> m && n && m) {
    int s[n][m];
    for(int i=0; i<n; i++) {
      string t;
      cin >> t;
      for(int j=0; j<m; j++) s[i][j]=z(t[j]);
    }
    int d[n][m];
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) d[i][j]=0;
    }
    d[0][0]=1;
    int ansx=-1,ansy=-1;
    int nx=0,ny=0;
    while(s[nx][ny]) {
      nx+=dx[s[nx][ny]];
      ny+=dy[s[nx][ny]];
      if(d[nx][ny]==0) d[nx][ny]=1;
      else break;
    }
    if(s[nx][ny]==0) {
      ansx=nx;
      ansy=ny;
    }
    if(ansx==-1 && ansy==-1) cout << "LOOP" << endl;
    else cout << ansy << " " << ansx << endl;
  }
  return 0;
}

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


char tile[100][100];
int h, w;
int ax, ay;
bool loop = false;


void solve(int x, int y){
	if (tile[y][x] == '>'){
		tile[y][x] = '*';
		solve(x + 1, y);
	}
	else if (tile[y][x] == '<'){
		tile[y][x] = '*';
		solve(x - 1, y);
	}
	else if (tile[y][x] == '^'){
		tile[y][x] = '*';
		solve(x, y - 1);
	}
	else if (tile[y][x] == 'v'){
		tile[y][x] = '*';
		solve(x, y + 1);
	}
	else if (tile[y][x] == '.'){
		ax = x;
		ay = y;
	}
	else if (tile[y][x] == '*'){
		loop = true;
	}
}


int main(){


	while (cin >> h >> w, h || w != 0){
		for (int y = 0; y < h; y++){
			for (int x = 0; x < w; x++){
				cin >> tile[y][x];
			}
		}
		solve(0, 0);
		if (!loop) cout << ax << ' ' << ay << endl;
		else cout << "LOOP" << endl;
		loop = false;
	}

	return 0;
}