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++: /*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    ll n;
    cin>>n;
    if(n==0) break;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    sort(ALL(v));
    vector<ll> ans(n-1);
    rep(i,n-1){
      ans[i]=abs(v[i]-v[i+1]);
    }
    sort(ALL(ans));
    cout<<ans[0]<<endl;
  }
}

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

int main() {
	int n;

	while (cin >> n, n) {
			vector<int> point(n);
			for (int i = 0; i < n; i++) {
				cin >> point[i];
			}
		
		sort(point.begin(), point.end());

		int ans = INFINITY;
		for (int i = 0; i < n; i++) {
			ans = min(ans, abs(point[i] - point[i+1]));
		}

		cout << ans << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    int n;
    while(cin>>n,n){
        vector<int> a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        sort(a.begin(),a.end());
        int res=INF;
        for(int i=1;i<n;i++){
            if(a[i]-a[i-1]<res){
                res=a[i]-a[i-1];
            }
        }
        cout<<res<<endl;
    }
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  VI xs(N);
  REP(i,N) cin >> xs[i];
  SORT(ALL(xs));

  int ans = 1e9;
  REP(i,N-1) ans = min(ans, xs[i+1]-xs[i]);

  cout << ans << endl;

  return 0;
}

C++: #include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

#define MAX 50000
int n, dif, a[MAX];

int main() {
	cin >> n;
	while (n) {
		dif = 1000000;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);

		for (int i = 0; i < n - 1; i++) {
			if (abs(a[i] - a[i + 1]) < dif) {
				dif = abs(a[i] - a[i + 1]);
			}
		}
		cout << dif << endl;

		cin >> n;
	}

	return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  while(1){
    int n; cin >> n; if(n == 0) break;
    vi a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    int minv = inf;
    rep(i,n-1) minv = min(minv, a[i+1] - a[i]);
    cout << minv << endl;
  }
}

C++: #include <iostream>
#include <cmath>
int n;
int a[1000];
int min = 1000000;

int main(){
  while(true){
    std::cin >> n;
    if(n == 0){
      break;
    }
    else{
      for(int i = 0; i < n; i++){
        std::cin >> a[i];
      }
      for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
           if(std::abs(a[i] - a[j]) < min){
             min = std::abs(a[i] - a[j]);
           }
        }
      }
      std::cout << min << std::endl;
      min = 1000000;
    }
  }
  return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int n;
	cin >> n;
	
	while (n!=0) {
		std::vector<int> a(n);
		int r;
		int rn;
		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++) {
				rn = std::abs(a[i] - a[j]);
				if (i==0 && j==1) {
					r = rn;
				} else {
					if (rn < r) {
						r = rn;
					}
				}
			}
		}
		cout << r << endl;
		cin >> n;
	}
	return 0;
}