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++: #include<bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		int a[n];
		for (int i = 0; i < n; ++i) cin>>a[i];
		sort(a,a+n);
		int ans=10000000;
		for (int i = 1; i < n; ++i) ans=min(ans,a[i]-a[i-1]);
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n;
	while(cin >> n && n) {
		vi a(n);
		rep(i, n) cin >> a[i];
		sort(all(a));
		int ans = INF;
		rep(i, n - 1) ans = min(ans, a[i+1] - a[i]);
		cout << ans << endl;
	}
}

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

int main() {
    int n;
    while (cin >> n and n) {
        vector<int> x(n);
        rep(i, n) cin >> x[i];
        sort(x.begin(), x.end());
        int ans=1e8;
        rep(i, n-1) {
            ans=min(ans, x[i+1]-x[i]);
        }
        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    ios::sync_with_stdio(false);
    vector<Int> res;
    while (true) {
        Int n;
        cin >> n;
        vector<Int> a(n);
        if (n == 0) break;
        for (Int i = 0; i < n; i++) cin >> a[i];
        sort(a.begin(), a.end());
        Int mi = 1e9;
        for (Int i = 0; i < n - 1; i++) mi = min(mi, a[i + 1] - a[i]);
        res.emplace_back(mi);
    }
    for (Int i = 0; i < (Int)res.size(); i++) dump(res[i]);
    return 0;
}

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

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int n;
    while (cin >> n, n) {
        vector<int> data(n);
        rep(i, n) {
            cin >> data[i];
        }
        sort(data.begin(), data.end());
        int ans = 1010001000;
        rep(i, n-1) {
            ans = min(ans, data[i+1] - data[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
    while(cin >> n, n){
    int a[1001]={0};
    for(int i=0; i<n; ++i)  cin >> a[i];
    sort(a, a+n);
    int minV=1000000;
    for(int i=1; i<n; ++i){
        minV = min(minV, abs(a[i]-a[i-1]));
    }
    cout << minV << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,i;
  int a[1001]={};
  while(1){
    int min = 1000001;
    cin >>n;
    if(n==0)break;
    for(i=0;i<n;++i){
      cin >>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;++i){
      if(a[i]-a[i+1]>=0){
	if(a[i]-a[i+1]<min)
	  min = a[i]-a[i+1];
      }else{
	if(a[i+1]-a[i]<min)
	  min = a[i+1]-a[i];
      }
    }
    cout << min << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int main(){
	while(1){
		int n;
		cin>>n;
		if(!n)break;
		int a[n];
		rep(i,n)cin>>a[i];
		sort(a,a+n);
		int ans=1000000;
		rep(i,n-1)ans=min(ans,a[i+1]-a[i]);
		cout<<ans<<endl;
	}
	return 0;
}

C++: /* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = (ll)1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int n;
int a[1000];

int main(){
  while (cin >> n, n){
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    int mn = inf;
    rep(i, n - 1) chmin(mn, a[i + 1] - a[i]);
    cout << mn << endl;
  }
}

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

using namespace std;

int n[1000]={};
long long a[1000][1000]={};
long long ans = 10000000000;

int main(){
    int s=0;
    while(1){
        scanf("%d",&n[s]);
        if(n[s] == 0){
            break;
        }
        for(int i=0;i<n[s];i++){
           scanf("%lld",&a[s][i]); 
        }
        s++;
    }

    int times =s;
    int sub;
    for(int i=0;i<s;i++){
        sort(a[i],a[i]+n[i]);
        for(int j=0;j<n[i]-1;j++){
            sub = abs(a[i][j] - a[i][j+1]);
            if(ans >= sub){
                ans = sub;
            }
        }
        cout << ans << endl;
        ans = 1000000000;
    }
    

    return 0;
}

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

int main(){
	while(1){
		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;
}