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 <iostream>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int main() {
    int n, min;
    vi a;
    while (cin >> n) {
        if (n == 0) break;

        min = 1e9;
        a.resize(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        sort(a.begin(), a.end());
        for (int i = 1; i < n; i++) {
            min = (a[i] - a[i-1] < min) ? a[i] - a[i-1] : min;
        }

        cout << min << endl;
    }

    return 0;
}

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

using namespace std;

int main(void){
    while (1){
        int n;
        cin>>n;

        if(n==0)break;

        int a[1010];
        for(int i=0; i<n;i++){
            cin>>a[i];
        }
        sort(a, a+n);
        int min_a = INT_MAX;
        for(int i=1; i<n; i++){
            min_a = min(min_a, abs(a[i-1]-a[i]));
        }
        cout<<min_a<<endl;
    }


    return 0;


}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    while (cin >> n, n) {
        vector<ll> v(n); cin >> v;
        ll ans = linf;
        rep(i, n) rep(j, i+1, n) chmin(ans, abs(v[i]-v[j]));
        cout << ans << endl;
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  while(true){
    int n;
    cin>>n;
    if(!n)break;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    int ans=1e9;
    for(int i=0;i<n-1;i++){
      ans=min(ans,abs(a[i]-a[i+1]));
    }
    cout<<ans<<endl;
  }
}

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

int main() {
	int n;

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

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

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#define SEISEKI 1000001

using namespace std;

int main() {
	while (1) {
		int n,data;
		int ans=SEISEKI;
		vector<int> a;

		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> data;
			a.push_back(data);
		}
		sort(a.begin(), a.end());	//昇順
		for (int i = 0; i< n; i++) {
			ans = min(ans,a[i]-a[i - 1]);
		}
		cout << ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<bitset>
#define DEBUG
using namespace std;
int main(){
  int n;
  while(cin >> n && n) {
    int num[n];
    for (int i = 0; i < n; i++) {
      cin >> num[i];
    }
    int min = 1000000;
    for (int i = 0; i < n; i++) {
      for (int j = i+1; j < n; j++) {
	if (min > abs(num[i]-num[j])) {
	  min = abs(num[i]-num[j]);
	}
      }
    }
    cout << min << endl;
  }




  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(;;){
        int n;
        cin>>n;
        if(!n) return 0;
        vector<int> a(n);
        rep(i,0,n) cin>>a[i];
        sor(a);
        int ans=1e8;
        rep(i,1,n) ans=min(ans, a[i]-a[i-1]);
        cout <<ans<<"\n";
    }
}

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

int a[1010101];

void sort(int l, int r) {
    if (l >= r) return;
    int p = l;
    int k = l+1;
    while (k <= r) {
        if (a[k] < a[l]) {
            swap(a[k], a[p+1]);
            p++;
        }
        k++;
    }
    swap(a[l], a[p]);
    sort(l, p);
    sort(p+1, r);
}

int main(void){
    int n;
    while (1) {
        cin >> n;
        if (!n) break;
        for (int i = 0; i < n; i++) cin >> a[i];
        sort(0,n-1);
        //for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
        
        int ans = 1000;
        for (int i = 0; i < n-1; i++) if (ans > a[i+1] - a[i]) ans = a[i+1] - a[i];
        cout << ans << endl;
    }    
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		vector<int> a;
		REP(i, n) {
			int tmp;
			cin >> tmp;
			a.push_back(tmp);
		}
		sort(a.begin(), a.end());
		int ans = 10000000;
		for (int q = 1; q < a.size(); ++q) {
			ans = min(ans, a[q] - a[q - 1]);
		}
		cout << ans << endl;
	}
}