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 <complex>
#include <map>

using namespace std;

typedef complex<int> P;

int main() {
	P dirs[5] = {
		P(0, 0),
		P(0, -1),
		P(1, 0),
		P(0, 1),
		P(-1, 0)
	};
	map<char, int> trans;
	trans['.'] = 0;
	trans['^'] = 1;
	trans['>'] = 2;
	trans['v'] = 3;
	trans['<'] = 4;

	int W, H;
	int m[100][100];
	while (cin >> H >> W, H || W) {
		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x)
				m[y][x] = trans[str[x]];
		}

		P p = P(0, 0);
		for (int i = 0; i < W*H; ++i)
			p += dirs[m[p.imag()][p.real()]];

		if (m[p.imag()][p.real()]) cout << "LOOP" << endl;
		else cout << p.real() << " " << p.imag() << endl;
	}
}

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<W;i++){
      for(int j=0;j<H;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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int H,W;
char field[110][110];
map<char,int> dx;
map<char,int> dy;

void make(){
  dx['^'] = 0;  dy['^'] = -1;
  dx['v'] = 0;  dy['v'] = 1;
  dx['>'] = 1;  dy['>'] = 0;
  dx['<'] = -1; dy['<'] = 0;
}

pair<int,int> func(int i, int j){
  if(field[i][j] == '.') return make_pair(i,j);
  int cnt = 0;

  while(1){
    if(i < 0 || j < 0 || i >= H || j >= W) continue;
    cnt++;
    i += dy[field[i][j]];
    j += dx[field[i][j]];
    if(field[i][j] == '.') return make_pair(i,j);
    if(cnt > 10000) break;
  }

  return make_pair(-1,-1);
}

int main(){
  int i,j,k;

  make();
  for(; ~scanf("%d %d",&H,&W); ){
    if(H == 0 && W == 0) break;

    rep(i,H) scanf("%s",&field[i]);

    pair<int,int> res = func(0,0), out(-1,-1);
    if(res == out) puts("loop");
    else printf("%d %d\n",res.second,res.first);
  }

  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int
#define RIGHT 1
#define UP 2
#define LEFT 3
#define DOWN 4
#define CLEARED 5

using namespace std;

int main()
{
	int H, W, x, y;
	int map[101][101];
	string buf;
	while(1){
		cin >> H >> W;
		if(H == 0) break;

		memset(map, 0, sizeof(int)*101*101);

		for(int i=0; i<H; i++){
			cin >> buf;
			for(int j=0; j<W; j++){
				if(buf[j] == '>') map[i][j] = RIGHT;
				else if(buf[j] == '^') map[i][j] = UP;
				else if(buf[j] == '<') map[i][j] = LEFT;
				else if(buf[j] == 'v') map[i][j] = DOWN;
			}
		}

		x = 0, y = 0;

		while(1){
			if(map[y][x] == CLEARED){
				cout << "LOOP" << endl;
				break;
			} else if(map[y][x] == RIGHT){
				map[y][x] = CLEARED;
				x++;
			} else if(map[y][x] == UP){
				map[y][x] = CLEARED;
				y--;
			} else if(map[y][x] == LEFT){
				map[y][x] = CLEARED;
				x--;
			} else if(map[y][x] == DOWN){
				map[y][x] = CLEARED;
				y++;
			} else {
				cout << x << ' ' << y << endl;
				break;
			}
		}
	}
	return 0;
}

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

int main(){
   int a, b, i, j;
   char map[102][102];
   
   while(1){
      cin >> a >> b;
      if(a+b==0) break;
      
      for(i=0; i< a; i++){
         for(j=0; j< b; j++){
            cin >> map[i][j];
         }
      }
      i=0,j=0;
      while(1){
         if(map[i][j]=='.'){
            cout << j << " " << i << endl;
            break;
         }else if(map[i][j]=='#'){
            cout << "loop" << endl;
            break;
         }else if(map[i][j]=='>'){
            map[i][j]='#';
            j++;
         }else if(map[i][j]=='<'){
            map[i][j]='#';
            j--;
         }else if(map[i][j]=='^'){
            map[i][j]='#';
            i--;
         }else if(map[i][j]=='v'){
            map[i][j]='#';
            i++;
         }
      }
   }
   return 0;
}

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

using namespace std;

typedef struct{
    int x;
    int y;
}dbint;

dbint move(char c){
    dbint mv;
    switch (c) {
        case '>':
            mv.x=1;
            mv.y=0;
            break;
        case '^':
            mv.x=0;
            mv.y=-1;
            break;
        case '<':
            mv.x=-1;
            mv.y=0;
            break;
        case 'v':
            mv.x=0;
            mv.y=1;
            break;
        default:
            mv.x=10;
            mv.y=10;
            break;
    }
    return mv;
}

int main() {
    int h,w,n=0;
    char c;
    dbint p,mv;
    vector< vector<char> > tiles;
    vector<char> temp;
    while(1){
        cin >> h >> w;
        p.x=0;p.y=0;
        if(h==0&&w==0) break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin >> c;
                temp.push_back(c);
            }
            tiles.push_back(temp);
            temp.clear();
        }
        while(1){
            mv=move(tiles[p.y][p.x]);
            if(mv.x>1) break;
            p.x+=mv.x;
            p.y+=mv.y;
            n++;
            if(n>h*w*10){
                n=-1;
                break;
            }
        }
        if(n>0) cout << p.x << " " << p.y << endl;
        else    cout << "LOOP" << endl;
        tiles.clear();
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
	while (true){
		char room[100][100];
		int H, W; cin >> H >> W;
		if (H == 0 && W == 0)return 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> room[i][j];
			}
		}
		pair<int, int>l;
		l.first = 0; l.second = 0;
		for (int i = 0; ; i++){
			if (i >= 100) {
				cout << "LOOP\n";
				goto Exit;
			}
			char c = room[l.first][l.second];
			if (c == '.') {
				cout << l.second << ' ' << l.first << endl;
				goto Exit;
			}
			if (c == '^')l.first--;
			else if (c == 'v')l.first++;
			else if (c == '<')l.second--;
			else if (c == '>')l.second++;
		}
	Exit:;
	}
}