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 <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int *array1, *array2, n, m, tmp, i, j;
	char w;
	
	while(1){
		cin >> n >> m;
		if(n == 0 || m == 0){
			break;
		}
		if(n*m > 2){
			array1 = (int *)calloc(n*m, sizeof(int));
			array2 = (int *)calloc(n*m, sizeof(int));
		} else {
			array1 = (int *)calloc(2, sizeof(int));
			array2 = (int *)calloc(2, sizeof(int));
		}
		
		
		for(i = 0; i < n; i++){
			for(j = 0, tmp = i*m; j < m; j++){
				cin >> w;
				
				if(w == '>'){
					array1[tmp+j] = tmp + j + 1;
				} else if(w == 'v'){
					array1[tmp+j] = tmp + j + m;
				} else if(w == '<'){
					array1[tmp+j] = tmp + j -1;
				} else if(w == '^'){
					array1[tmp+j] = tmp + j - m;
				} else {
					array1[tmp+j] = -1;
				}
			}
		}
		
		tmp = array1[0];
		array2[0] = 1;
		while(1){
			if(array2[tmp] == 1){
				cout << "LOOP" << endl;
				break;
			} else if(array1[tmp] == -1){
				i = tmp % m;
				j = (int)(tmp / m);
				cout << i << " " << j << endl;
				break;
			}
			
			array2[tmp] = 1;
			tmp = array1[tmp];
		}		
		
		free(array1);
		free(array2);
	}
	
	
	return 0;
}

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

int main(void) {
  char G[2000][2000];
  bool visited[2000][2000];
  int W, H;
  string str;
  
  while(cin >> W >> H) {
    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++: import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int h = sc.nextInt();
                int w = sc.nextInt();
                while(h != 0){
                        sc.nextLine();
                        char[][] map = new char[h][w];
                        boolean[][] passed = new boolean[h][w];
                        int[] xy = new int[2];
                        passed[0][0] = true;
                        for(int i = 0 ; i < h ; i++){
                                String s = sc.nextLine();
                                for(int j = 0 ; j < w ; j++){
                                        map[i][j] = s.charAt(j);
                                }
                        }
                        System.out.println((move(map, xy, passed) == 1) ? xy[0] + " " + xy[1] : "LOOP");
                        h = sc.nextInt();
                        w = sc.nextInt();
                }
        }
        static int move(char[][] map, int[] xy, boolean[][] passed){
                switch(map[xy[1]][xy[0]]){
                        case '>':
                                xy[0]++;
                                break;
                        case '<':
                                xy[0]--;
                                break;
                        case '^':
                                xy[1]--;
                                break;
                        case 'v':
                                xy[1]++;
                                break;
                        case '.':
                                return 1;
                }
                if(passed[xy[1]][xy[0]]){
                        return -1;
                }else{
                        passed[xy[1]][xy[0]] = true;
                        return move(map, xy, passed);
                }
        }
}

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;
		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;

		}
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	int H, W;
	while (cin >> H, cin >> W, !(H == 0 && W == 0)){
		struct Locate{
			int x;
			int y;
		};
		vector<vector<char>> map;
		vector<vector<bool>> loop_flag;
		Locate pos;
		pos.x = 0;
		pos.y = 0;
		map.resize(H);
		loop_flag.resize(H);
		for (int i = 0; i < H; i++){
			map[i].resize(W);
			loop_flag[i].resize(W);
			for (int j = 0; j < W; j++){
				cin >> map[i][j];
				loop_flag[i][j] = false;
			}
		}
		bool eflag = false;
		while (!eflag){
			if (loop_flag[pos.y][pos.x] == false){
				loop_flag[pos.y][pos.x] = true;
			}
			else{
				cout << "LOOP\n";
				eflag = true;
				continue;
			}
			if (map[pos.y][pos.x] == '>'){

				pos.x += 1;
			}
			else if (map[pos.y][pos.x] == 'v'){
				pos.y += 1;
			}
			else if (map[pos.y][pos.x] == '^'){
				pos.y -= 1;
			}
			else if (map[pos.y][pos.x] == '<'){
				pos.x -= 1;
			}
			else if (map[pos.y][pos.x] == '.'){
				eflag = true;
				cout << pos.x << " " << pos.y << "\n";
			}
		}
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
char s[101][101];
int n,m,a[100][100],c;
using namespace std;
void dfs(int y,int x){
  if(c)goto Z;
  if(a[y][x]++)goto L;
  if(s[y][x]=='.'){cout<<x<<' '<<y<<endl;c++;}
  else if(s[y][x]=='^')dfs(y-1,x);
  else if(s[y][x]=='v')dfs(y+1,x);
  else if(s[y][x]=='>')dfs(y,x+1);
  else if(s[y][x]=='<')dfs(y,x-1);
  L:cout<<"LOOP"<<endl;c++;Z:;
}
int main(){
  while(cin>>n>>m,n){c=0;
    rep(i,100)rep(j,100)a[i][j]=0;
    rep(i,n)rep(j,m)cin>>s[i][j];dfs(0,0);
  }
}

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

int orLoop, x, y, d, HW, H, W;
string input[10];

int loop(int a, int b){
	if (d > HW) { 
		orLoop = true;
		return 0;
	}
	char i = input[b][a];
	if(i=='>'){
		d++;
		loop(a + 1, b);
	}
	else if(i=='v'){
		d++;
		loop(a, b + 1);
	}
	else if(i=='<'){
		d++;
		loop(a - 1, b);
	}
	else if(i=='^'){
		d++;
		loop(a, b - 1);
	}
	else{
		x = a;
		y = b;
		return 0;
	}
	return 0;
}

int main(){
	while(cin >> H >> W){
		if (H == 0 && W == 0) { break; }
		else { HW = H*W + 2; }

		for(int i = 0;i<H;i++){
			cin >> input[i];
		}
		d = 0;
		orLoop = false;
		loop(0, 0);
		if(orLoop){
			cout << "LOOP" << endl;
		}
		else{
			cout << x << " " << y << endl;
		}
	}
	return 0;
}