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<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int w,h;
   bool flag=false;
   char map[100+5][100+5];
   while(cin>>h>>w&&(w||h))
   {
     int map2[100+5][100+5]={{0}};
     for(int i=0;i<h;i++)
     {
       for(int j=0;j<w;j++)
       {
         cin>>map[i][j];        
       }        
     }               
     int step=0;
     int x=0;
     int y=0;
     while(1)
     {
       if(map2[x][y]==1) 
       {
         flag=true;
         break;                  
       }
       if(map[x][y]=='>') 
       {
         map2[x][y]=1;
         y++;
         step++;
         //cout<<">"<<" ";                      
       }        
       if(map[x][y]=='<')
       {
         map2[x][y]=1;
         y--;
         step++;   
         //cout<<"<"<<" ";                   
       }
       if(map[x][y]=='v')
       {
         map2[x][y]=1;
         x++;
         step++;         
         //cout<<"v"<<" ";             
       }
       if(map[x][y]=='^')
       {
         map2[x][y]=1;
         x--;
         step++;         
         //cout<<"^"<<" ";             
       }
       if(step>(w*h))
       {
         flag=true;
         break;            
       }
       if(map[x][y]=='.')
       {
         break;                  
       }
       if(flag) break;
     }        
     if(flag) cout<<"LOOP"<<endl;
     else cout<<y<<" "<<x<<endl;
   }
   //while(1);
   return 0;
 }

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<cstdio>
#include<climits>
#include<cfloat>
#include<cstring>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define rforeach(t,p) for(t::reverse_iterator it=p.rbegin();it!=p.rend();++it)
#define all(p) p.begin(),p.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define FOREACH(t,p,tit) for(t::iterator tit=p.begin();tit!=p.end();++tit)
using namespace std;
char tiles[102][102];

int main()
{
    int w,h;
    while(cin >> w >> h)
    {
        if(w==0&&h==0){break;}
        rep(j,h)rep(i,w){cin >> tiles[i][j];}

        int x,y,nextx,nexty;
        x=0;
        y=0;
        int loop = 0;
        while(1)
        {
            if(tiles[x][y]=='.'){break;}
            if(tiles[x][y]=='x'){loop=1;break;}

            if(tiles[x][y]=='>')
            {
                nextx = x+1;nexty = y;
                tiles[x][y] = 'x';
                x = nextx;y = nexty;
                continue;
            }
            if(tiles[x][y]=='<')
            {
                nextx = x-1;nexty = y;
                tiles[x][y] = 'x';
                x = nextx;y = nexty;
                continue;
            }
            if(tiles[x][y]=='v')
            {
                nextx = x;nexty = y+1;
                tiles[x][y] = 'x';
                x = nextx;y = nexty;
                continue;
            }
            if(tiles[x][y]=='^')
            {
                nextx = x;nexty = y -1;
                tiles[x][y] = 'x';
                x = nextx;y = nexty;
                continue;
            }
        }
        if(loop){cout << "LOOP"<<endl;continue;}
        cout <<x << " "<<y << endl;

    }

    return 0;
}

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

int main(void) {
  char G[200][200];
  bool visited[200][200];
  int W, H;
  string str;
  
  while(cin >> H >> W) {
    if(W==0 && H==0) break;
    for(int i=0; i<H; i++) {
      cin >> str;
      for(int j=0; j<W; j++) {
	G[i][j] = str[j];
	visited[i][j] = false;
      }
    }
    
    int x=0, y=0;
    while(1) {
      if(visited[y][x]) { cout << "LOOP" << endl; break; }
      
      visited[y][x] = true;
      if(G[y][x] == '>') x++;
      else if(G[y][x] == 'v') y++;
      else if(G[y][x] == '^') y--;
      else if(G[y][x] == '<') x--;
      else if(G[y][x] == '.') { cout << x << " " << y << endl; break; }
    }

  }
  
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair



int main(){
    typedef vector<string> vs;
    int h,w;
    while(cin>>h>>w, h|w){
        vs G(h);
        for(auto & a: G) cin>>a;

        vector<vector<bool>> vis(h, vector<bool>(w,false));
        int cx = 0, cy = 0;
        const int dx[] = {1,0,-1,0};
        const int dy[] = {0,-1,0,1};

        map<char,int> m;
        m['>'] = 0, m['^'] = 1, m['<'] = 2, m['v'] = 3;

        while(1){
            if(vis[cy][cs]){
                cout << "LOOP" << endl;
                goto end;
            }
            vis[cy][cx] = true;
            char c = G[cy][cx];
            if(c=='.'){
                cout << cx << " " << cy << endl;
                goto end;
            }
            cx += dx[m[c]], cy += dy[m[c]];
        }
    end:;
    }
}

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

char masu[101][101];
int H,W,x,y;



int main()
{
	int i,j;
	int f,t1,t2;
	char temp;
	
	for(;;){
		x=0;
		y=0;
		f=0;
		
		scanf("%d %d", &H, &W);
		if(H==0)break;
		scanf("%c",&temp);
		
		for(i=0;i<H;i++){
			for(j=0;j<W+1;j++){
				scanf("%c",&masu[i][j]);
			}
		}
		for(;;){
			if(masu[y][x]==','){
				f=1;
				break;
			}
			t1=x;
			t2=y;
			if(masu[y][x]=='>')x++;
			else if(masu[y][x]=='<')x--;
			else if(masu[y][x]=='v')y++;
			else if(masu[y][x]=='^')y--;
			else if(masu[y][x]=='.')break;
			masu[t2][t1]=',';
		}
		if(f==1)puts("LOOP");
		else printf("%d %d\n",x,y);
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
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]!='.'){
			//printf("%c\n", 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';
			}
			
			//printf("%d %d\n", x, y);
		}
		
		if(loop) printf("LOOP\n");
		else printf("%d %d\n", x, y);
	}
}