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 <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int h, w;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	std::cin.rdbuf(ifs.rdbuf());
#endif

	while(std::cin >> h >> w){
		if(h == 0 && w == 0){ break; }
		std::vector<std::string> image;
		std::vector<std::vector<bool> >  is_visited(h, std::vector<bool>(w, false));
		int x = 0;
		int y = 0;

		for(int y = 0; y < h; y++){
			std::cin >> buf;
			image.push_back(buf);
		}

		while(true){
			if(image[y][x] == '.'){
				std::cout << x << " " << y << std::endl;
				break;
			}
			if(is_visited[y][x]){
				std::cout << "LOOP" << std::endl;
				break;
			}
			is_visited[y][x] = true;
			switch(image[y][x]){
			case '>':
				x++;
				break;
			case '<':
				x--;
				break;
			case '^':
				y--;
				break;
			case 'v':
				y++;
				break;
			default:
				break;
			}
		}
	}


#if INPUT_FROM_FILE
		//fclose(fp);
#endif
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#define rep(i,n) for(i=0;i<(n);++i)
int n, m, i, j, x, y, loop;
char buf[102];
char tile[102][102];
bool visited[102][102];

int main()
{
    while (true) {
        fgets(buf, 102, stdin);
        sscanf(buf, "%d %d", &n, &m);
        if (!(m|n)) break;

        rep(i, n) rep(j, m) visited[i][j] = false;
        rep(i, n) fgets(tile[i], 102, stdin);
        x = y = loop = 0;
        visited[y][x] = true;
        while (tile[y][x] != '.') {
            switch (tile[y][x]) {
                case '>': x++; break;
                case 'v': y++; break;
                case '<': x--; break;
                case '^': y--; break;
            }
            if (visited[y][x]) { loop = 1; break; }
            visited[y][x] = true;
        }
        if (loop) puts("LOOP"); else printf("%d %d\n", x, y);
    }
    return 0;
}

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

int main(){
  while(1){
    int h, w;
    bool flag;
    cin >> h >> w;
    if(h==0 && w==0) break;
    getchar();

    bool p[N][N];
    char data[N][N];

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> data[i][j];
	p[i][j]=false;
      }
    }

    int x=0, y=0;
    flag=false;
    while(1){
      if(p[y][x]){
	flag=true;
	break;
      }
      p[y][x]=true;
      if(data[y][x]=='>'){
	x++;
      }
      else if(data[y][x]=='<'){
	x--;
      }
      else if(data[y][x]=='^'){
	y--;
      }
      else if(data[y][x]=='v'){
	y++;
      }
      else if(data[y][x]=='.'){
	break;
      }
    }
    if(flag) cout << "LOOP" << endl;
    else cout << x << ' ' << y << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;
int H, W;
int x = 0, y = 0;
int rog[100][100];
bool check(){
	if (rog[x][y] == 0){
		cout << "LOOP" << endl;
		return true;
	}
	
		return false;
	
}
int main(){
	char ma[100][100];

	while (cin >> H >> W,W+H){

		int x = 0, y = 0;
		ma[100][100] = {};
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cin >> ma[j][i];
				rog[j][i] = 1;
			}
		}
		while (1){
			if (ma[x][y] == '>'){
				x++;
				if (check())break; 
			}
			else if(ma[x][y]=='v'){
				y++;
				if (check()) break; 
			}
			else if (ma[x][y] == '<'){
				x--;
				if (check()) break; 
			}
			else if (ma[x][y] == '^'){
				y--;
				if (check())break; 
			}
			else {
				cout << x << " " << y << endl;
				break;
			}
			
			rog[x][y] = 0;

		}
	}
	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))
	{
		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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int W,H;
char s;


int main(){
    while(cin>>H>>W){
        if(W==0&&H==0)break;
        
        int tile[2][101][101]={0};
        bool pass[101][101]={0};
        
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cin>>s;
                if(s=='>'){
                    tile[0][i][j]=0;
                    tile[1][i][j]=1;
                }else if(s=='<'){
                    tile[0][i][j]=0;
                    tile[1][i][j]=-1;
                }else if(s=='^'){
                    tile[0][i][j]=-1;
                    tile[1][i][j]=0;
                }else if(s=='v'){
                    tile[0][i][j]=1;
                    tile[1][i][j]=0;
                }else if(s=='.'){
                    tile[0][i][j]=0;
                    tile[1][i][j]=0;
                }
            }
        }
        
        int now_w=0,now_h=0;
        while(1){
            //cout<<now_w<<" "<<now_h<<endl;
            
            if(tile[0][now_h][now_w]==0&&tile[1][now_h][now_w]==0)break;
            if(pass[now_h][now_w]==true){
                now_w=-1;
                now_h=-1;
                break;
            }
            
            pass[now_h][now_w]=true;
            int temp_h,temp_w;
            temp_h=now_h+tile[0][now_h][now_w];
            temp_w=now_w+tile[1][now_h][now_w];
            now_h=temp_h;
            now_w=temp_w;
            
        }
        
        if(now_h==-1){
            cout<<"LOOP"<<endl;
        }else{
            cout<<now_w<<" "<<now_h<<endl;
        }
        
        
        
        
    }
    
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int h,w;
  while(cin >>h>>w,h||w){
    int field[100][100] = {0};
    bool f[100][100] = {false};
    string s;
    for(int i=0; i<h; i++){
      cin >>s;
      for(int j=0; j<s.size(); j++){
	if(s[j] == '>'){field[i][j] = 1;}
	if(s[j] == 'v'){field[i][j] = 2;}
	if(s[j] == '<'){field[i][j] = 3;}
	if(s[j] == '^'){field[i][j] = 4;}
      }
    }
    int px, py;
    px = py = 0;
    for(;;){
      if(f[py][px]){cout <<"LOOP"<<endl;break;}
      f[py][px] = true;
      if(!field[py][px]){cout <<px<<" "<<py<<endl;break;}
      if(field[py][px] == 1){px++;}
      if(field[py][px] == 2){py++;}
      if(field[py][px] == 3){px--;}
      if(field[py][px] == 4){py--;}
    }
  }
  return 0;
}