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++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define INF 1LL << 55
#define MAX (1LL << 31) -1
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;
typedef pair<pair<int,int>,ll> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};
//#define F function<T(T,T)>


signed main(){
    while(true){
        int n;
        cin>>n;
        if(n==0) return 0;
        vector<int> v(n);
        for(int i=0;i<n;i++) cin>>v[i];
        sort(v.begin(),v.end());
        int ans=MAX;
        for(int i=0;i<n-1;i++){
            chmin(ans,v[i+1]-v[i]);
        }
        cout<<ans<<endl;
    }
}

C++: #include<bits/stdc++.h>
#define MAX 1024
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int n;
int a[MAX];

int main()
{
  while(cin>>n && n){
    FOR(i,0,n)cin>>a[i];
    sort(a,a+n);
    int ans=inf;
    FOR(i,1,n)ans=min(ans,a[i]-a[i-1]);
    cout<<ans<<endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

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

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

		VI a(n);
		rep(i, n)cin >> a[i];
		SORT(a);
		int ans = INT_MAX;
		rep(i, n - 1) {
			int x = a[i + 1] - a[i];
			if (ans > x)ans = x;
		}
		cout << ans << endl;
	}
}

C++: 

using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#define out(S) cout<<(S)<<endl;
#define mod(i) ((i)%(ll)(1000000000 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define For(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFor(i,a,b) for(size_t i=(a)-1;i>=(b);i--)
#define Rep(i,a) for(size_t i=0;i<(a);i++)
#define rRep(i,a) for(size_t i=(a)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)

int main(){
	int N;
	cin >> N;
	vector<ll> ans;
	while (N!=0)
	{
		vector<ll> a;
		a.resize(N);
		Rep(i, N) cin >> a[i];
		ll thismin = 1e10;
		Rep(i, N) {
			Rep(n, N) {
				if (n == i) continue;
				thismin = min(thismin, abs(a[i] - a[n]));
			}
		}
		ans.push_back(thismin);
		cin >> N;
	}
	Foreach(i, ans) out(i);
	return 0;
}

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

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

    if(n==0)
      break;

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

    int dif = 1000001;

    for(int i=0; i<n-1; i++){
      for(int j=i+1; j<n; j++){
        int d = abs(a[i]-a[j]);

        if(d<dif){
          dif = d;
        }
      }
    }
    cout << dif << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,a[1111],ans;
	cin >> n;
	while(n){
		ans = INF;
		for(i=0; i<n; ++i){
			cin >> a[i];
		}
		sort(a,a+n);
		for(i=1; i<n; ++i){
			ans = min(ans,a[i]-a[i-1]);
		}
		cout << ans << endl;
		cin >> n;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,e) for(int i=0;i<(e);++i)

int main() {
  int n;
  while(cin >> n){
    if(n==0) return 0;
    int ans = 1e9;
    vector<int> v(n);
    rep(i, n){
      cin >> v[i];
    }
    sort(v.begin(), v.end());
    REP(i, 1, n){
      ans = min(ans, abs(v[i-1]-v[i]));
    }
    cout << ans << endl;
  }
  return 0;
}

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

int a[1010];

int main(){
	int n,min;
	while(1){
		cin>>n;
		if(n==0) break;
		min=10000000;
		for(int i=0;i<n;i++) cin>>a[i];
		int f=1;
		while(f!=0){
			f=0;
			for(int j=0;j<n-1;j++){
				if(a[j]>a[j+1]){
					swap(a[j],a[j+1]);
					f++;
				}
			}
		}
		for(int i=n-1;i>0;i--){
			if(min>a[i]-a[i-1]) min=a[i]-a[i-1];
		}
		cout<<min<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define INF 1000000000

int main()
{
	int n;
	while (cin >> n, n) {
		vector<int> a;
		REP(i, 0, n) {
			int in;
			cin >> in;
			a.push_back(in);
		}

		sort(a.begin(), a.end());
		int ans = INF;
		REP(i, 0, a.size() - 1) {
			ans = min(ans, a[i + 1] - a[i]);
		}

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

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

using namespace std;

int main(){
  int a[1001];

  int c[1001];

  int b, mn;

  mn = 1000000;

  while(1){

    cin >> b;

    if(b == 0) break;

    for(int i=0;i<b;i++){
      cin >> a[i];
    }
    for(int j=0;j<b+b;j++){
      for(int i=0;i<b;i++){
	if(a[i] < a[i+1]) swap(a[i],a[i+1]);
      }
    }
    for(int i=0;i<b-1;i++){
      c[i] = a[i] - a[i+1];
    }

    for(int i=0;i<b-1;i++){
      if(c[i]<mn) mn = c[i];
    }

    cout << mn << endl;

  }


}