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<cstdio>
#include<string>
using namespace std;
int h,w;
string ss[100];
bool x[100][100];
int ans1=0,ans2=0;
bool ans=true;
bool f(){
	while(true){
		if(ss[ans1][ans2]=='.')return true;
		else if(!x[ans1][ans2])return false;
		else if(ss[ans1][ans2]=='>'){
			x[ans1][ans2]=false;
			ans2++;
			f();
		}
		else if(ss[ans1][ans2]=='<'){
			x[ans1][ans2]=false;
			ans2--;
			f();
		}
		else if(ss[ans1][ans2]=='v'){
			x[ans1][ans2]=false;
			ans1++;
			f();
		}
		else{
			x[ans1][ans2]=false;
			ans1--;
			f();
		}
	}
}
int main()
{
	while(true){
		scanf("%d%d",&h,&w);
		if(h==0&&w==0)return 0;
		for(int i=0;i<h;i++)cin >> ss[i];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)x[i][j]=true;
		ans1=0,ans2=0;
		ans=true;

		if(f()){
		    cout << ans1 << " " << ans2 << "\n";
		}
		else cout << "LOOP" << "\n";
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	struct POINT {int x, y;} p;
	int w, h, i, j, c;
	char f[100][100];
	bool b;
	while (cin >> w >> h)
	{
		if (w == 0 && h == 0) break;
		p.x = p.y = 0;
		b = false;
		c = 0;
		for (i = 0; i < w; i++)
			for (j = 0; j < h; j++)
				cin >> f[i][j];
		while (c <= w*h)
		{
			switch (f[p.y][p.x])
			{
			case '>':
				p.x++;
				break;
			case '^':
				p.y--;
				break;
			case '<':
				p.x--;
				break;
			case 'v':
				p.y++;
				break;
			default:
				cout << p.x << " " << p.y << endl;
				b = true;
				break;
			}
			if (b) break;
			c++;
		}
		if (!b) cout << "LOOP" << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

int H, W;
char c[110][110];
bool g;		
bool f[110][110];
int gy, gx;
void solve(int y, int x){
	if (f[y][x]){
		cout << "LOOP\n";
		return;
	}
	if (c[y][x] == '.'){
		cout << x << " " << y << endl;
		return;
	}	
	f[y][x] = 1;
	if (c[y][x] == '>'){
		solve(y, x + 1);
	}
	else if (c[y][x] == 'v'){
		solve(y + 1, x);
	}
	else if (c[y][x] == '<'){
		solve(y, x - 1);
	}
	else{
		solve(y - 1, x);
	}
}

int main(){
	while (cin >> H >> W){
		if (H + W == 0)break;
		REP(i, H){
			REP(j, W){
				cin >> c[i][j];
			}
		}
		solve(0, 0);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

string s[111];
int xx, yy;
int h, w;

int solve(int x, int y){

  if(s[y][x] == '.'){ xx = x, yy = y; return true; }
  if(x == w || y == h || x < 0 || y < 0) return false;
  if(s[y][x] == '~') return false;

  char c = s[y][x];
  s[y][x] = '~';

  int ret = false;
  if(c == '>') ret |= solve(x+1, y);
  if(c == '<') ret |= solve(x-1, y);
  if(c == 'v') ret |= solve(x, y+1);
  if(c == '^') ret |= solve(x, y-1);

  return ret;

}

int main(){

  while(cin >> h >> w, h){
    
    for(int i=0;i<h;i++) cin >> s[i];
    
    if(solve(0, 0)) cout << xx << " " << yy << endl;
    else cout << "LOOP\n";
  }
  
}

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

using namespace std;

char d[101][101];
int X,Y;
bool Flag;

void solve(int x,int y){
  if(d[x][y]=='.'){
    Flag=1;
    X=x;Y=y;
    return;
  }
  if(d[x][y]==-1){
    return;
  }
  if(d[x][y]=='>'){
    d[x][y]=-1;
    solve(x,y+1);
  }
  if(d[x][y]=='<'){
    d[x][y]=-1;
    solve(x,y-1);
  }
  if(d[x][y]=='v'){
    d[x][y]=-1;
    solve(x+1,y);
  }
  if(d[x][y]=='^'){
    d[x][y]=-1;
    solve(x-1,y);
  }
  return;
}

int main(){
  int h,w;
  while(cin>>h>>w,h!=0&&w!=0){
    for(int i=0;i<h;i++){
      cin>>d[i];
    }
    Flag=0;
    solve(0,0);
    if(Flag){
      printf("%d %d\n",Y,X);
    }else{
      printf("LOOP\n");
    }
  }
  return 0;
}

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

using namespace std;

int H, W;

int ans_x, ans_y;

string str[500];

bool map[500][500];

bool search(int x, int y){
	if(x < 0 || x >= W || y < 0 || y >= H){
		return false;
	}
	
	if(map[y][x]){
		return false;
	}
	
	map[y][x] = true;
	
	if(str[y][x] == '.'){
		ans_x = x;
		ans_y = y;
		return true;
	}else if(str[y][x] == '^'){
		return search(x, y - 1);
	}else if(str[y][x] == 'v'){
		return search(x, y + 1);
	}else if(str[y][x] == '<'){
		return search(x - 1, y);
	}else if(str[y][x] == '>'){
		return search(x + 1, y);
	}
}

int main(){
	
	cin >> H >> W;
	
	while(H != 0 || W != 0){
		
		for(int i = 0; i < H; i++){
			cin >> str[i];
		}
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				map[i][j] = false;
			}
		}
		
		if(search(0,0)){
			printf("%d %d\n", ans_x, ans_y);
		}else{
			printf("LOOP\n");
		}
		
		cin >> H >> W;
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void)
{
	char field[102][102];
	int h, w;
	char come[102][102];
	
	while (1){
		int x, y;
		
		scanf("%d%d", &h, &w);
		
		if (h == 0){
			break;
		}
		
		memset(come, 0, sizeof(come));
		
		for (int i = 0; i < h; i++){
			scanf("%s", field[i]);
		}
		
		
		x = y = 0;
		while (come[y][x] == 0 && field[y][x] != '.'){
			come[y][x] = 1;
			
			switch (field[y][x]){
			  case '>':
			  	x++;
				break;
			  case '<':
			  	x--;
				break;
			  case '^':
			  	y--;
				break;
			  case 'v':
			  	y++;
				break;
			}
		}
		
		
		if (come[y][x] == 1){
			puts("LOOP");
		}
		else {
			printf("%d %d\n", x, y);
		}
	}
	
	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 << i << " " << j << 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<bits/stdc++.h>
using namespace std;

int main() {

  int w, h;
  while( cin >> h >> w, w+h ) {
    char room[101][101];
    int t = 0;
    int now_x = 0, now_y = 0;

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

    while(1) {
      if( room[now_y][now_x] == '.' ) break;
      char c = room[now_y][now_x];
      if( c == '>' ) now_x++;
      if( c == '<' ) now_x--;
      if( c == 'v' ) now_y++;
      if( c == '^' ) now_y--;
      t++;
      if( t > w * h ) break;
    }

    if( t > w * h ) cout << "LOOP" << endl;
    else cout << now_x << " " << now_y << endl;
  }
}