Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		an := make([]int, n)
		min := 1000000
		for i := 0; i < n; i++ {
			an[i] = nextInt()
		}
		sort.Ints(an)
		for i := 1; i < n; i++ {
			sub := an[i] - an[i-1]
			if min > sub {
				min = sub
			}
		}
		fmt.Println(min)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

C++: #define fn auto
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
void iput(int input) {put(input);}
void lput(long long input) {put(input);}

fn main() -> int {
  int n, in, prev, min, sa;
  vector<int> input;
  while(true){
    cin >> n;
    if(n != 0){
      for(int i=0; i<n; i++){
        cin >> in;
        input.push_back(in);
      }
      sort(input.begin(), input.end());
      min = 1000000;
      for(int i=1; i<n; i++){
        sa = abs(input[i-1] - input[i]);
        min = min > sa ? sa : min;
      }
      iput(min);
    }else{
      break;
    }
  }
}

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


int main() {

	vector<int> result;
	while (true)
	{
		
		int n;
		int a[50000];
		cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}

		sort(a, a + n);
		int res = 1000000000;
		for (int i = 0; i < n - 1; i++) {
			if (res > a[i + 1] - a[i]) {
				res = a[i + 1] - a[i];
			}
		}
		result.push_back(res);
		
	}	

	for (int i = 0; i < result.size; i++)
	{
		cout << result[i] << endl;
	}

}

C++: #include <iostream>
#include <cmath>
#include <utility>
#include <functional>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n;
	cin >> n;

	while (n) {
		vector<int> point(n);
		rep(i, 0, n) cin >> point[i];

		SORT(point);
		REV(point);
		int ans = point[0] - point[1];
		rep(i, 1, n - 1) {
			int sub = point[i] - point[i + 1];
			ans = min(ans, sub);
		}
		cout << ans << endl;

		cin >> n;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int n;

    while (true) {
        int n; cin >> n;
        if (n == 0) break;

        vector<int> a(n);

        rep(i, n) cin >> a.at(i);
        sort(a.begin(), a.end());

        int ans = a.at(1) - a.at(0);
        for (int i = 1; i < n; i++) {
            ans = min(ans, a.at(i) - a.at(i-1));
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;

int main() {
	while (1) {
		int n, k[1005], ans = INF;
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; ++i) {
			cin >> k[i];
		}
		sort(k, k + n);
		for (int i = 1; i < n; ++i) {
			ans = min(ans, abs(k[i] - k[i - 1]));
		}
		cout << ans << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans,t;
  int a[1000];
  while(1){
  cin >> n;
  if(n==0) break;
  for(int i=0; i<n; i++){
	cin >> a[i];
  }
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
	t = a[i] - a[j];
	if(t<0) t = t*(-1);
	if(i==0 && j==i+1) ans = t;
	ans = min(ans,t);
    }
  }
  cout << ans << endl;
  }
  return 0;
}

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

int main() {

    while(true) {

        int n;

        cin >> n;

        if(n==0) break;

        int a[n];

        for(int i=0; i<n; i++){
            cin >> a[i];
        }

        sort(a, a+n);

        priority_queue<int> q;

        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                q.push(a[i] - a[j]);
            }
        }

        cout << -q.top() << endl;

    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MAX 100000
const long long INF=1145141919,MOD=1e9+7;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const double EPS = 1e-9;    // 許容誤差。問題によって変える
//typedef complex<double> P;  // Point
//typedef vector<P> VP; //単純多角形
//#define X real()
//#define Y imag()
//#define LE(n,m) ((n) < (m) + EPS)
//#define GE(n,m) ((n) + EPS > (m))
//#define EQ(n,m) (abs((n)-(m)) < EPS)
//namespace std{
//    bool operator < (const P a, const P b){
//        return a.X != b.X ? a.X <b.X : a.Y < b.Y;
//    }
//}
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
//外積cross(a,b) = |a||b|sinθ
//double cross(const P& a, const P& b) {
 // return imag(conj(a)*b);
//}
//内積dot(a,b) = |a||b|cosθ
//double dot(const P& a, const P& b) {
  //return real(conj(a)*b);
//}
//Line
//struct L : public vector<P> {
  //L(const P &a, const P &b) {
    //push_back(a); push_back(b);
  //}
//};
//円
//struct C{
//  P p; double r;
//  C(const P &p, double r) : p(p), r(r) { }
//};
int main(){
    int n;
    cin>>n;
    while(n){
        int a[n]={};
        for(int i=0;i<n;i++) cin>>a[i];
        sort(a,a+n);
        int ans=INF;
        for(int i=0;i<n-1;i++){
            if(a[i+1]-a[i]<ans) ans=a[i+1]-a[i];
        }
        cout<<ans<<endl;
        cin>>n;
    }
    return 0;
}

C++: #include<bits/stdc++.h>

#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
#define FIX <<fixed<<setprecision(10)<<
using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;

class Stack{
private:
int m[1000];
int tp;
public:
    Stack(){
    tp=0;
    }
    void push(int x){
        tp++;
        m[tp]=x;
    }
    int pop(){
        tp--;
        return m[tp+1];
    }
}; 
class Queue{
private:
pair<string,int> m[60000];
int head,tail;
public:
    Queue(){
        head=0;
        tail=0;
    }
    bool isEmpty(){
        return head==tail;
    }
    void enqueue(pair<string,int> x){
        m[tail]=x;
        if(tail +1 ==60000)tail=0;
        else tail++;
    }
    pair<string,int> deque(){
        pair<string,int> x=m[head];
        if(head+1==60000)head=0;
        else head++;
        return x;
    } 
};

int main(){
ll n;
while(1){
ll min=0;
cin>>n;
if(n==0)break;
ll A[n];
REP(i,n)cin>>A[i];
min=abs(A[1]-A[0]);
REP(i,n-1)FOR(j,i+1,n)min= min<abs(A[j]-A[i])? min:abs(A[j]-A[i]);
cout<<min<<endl;
}
}