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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vi b;
    loop(i, 1, n) b.pb(a[i] - a[i - 1]);
    cout << *min_element(all(b)) << endl;
  }
}

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

using namespace std;

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

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
#define IINF (1<<21)
typedef long long ll;

int main() {
  int n;
  int a[1000100];

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

    REP(i, n) {
      cin >> a[i];
    }

    sort(a, a + n);

    int mind = IINF;
    FOR(i, 1, n) {
      mind = min(mind, a[i] - a[i - 1]);
    }
    cout << mind << endl;
  }

  return 0;
}

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

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

C++: #include<iostream>
#include<algorithm>
#define SEISEKI 10000000

using namespace std;

int main() {
	while (1) {
		int n;
		int ans=SEISEKI;

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

		sort(a, a+n);	//昇順

		for (int i = 0; i< n; i++) {
			for (int j = n - 1; j > 0; i--) {
				ans = min(ans, a[i] - a[i - j]);
			}
		}
		cout << ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        sort(v.begin(), v.end());
        int ans = INF<int>;
        for (int i = 0; i < n-1; ++i) {
            ans = min(ans, v[i+1]-v[i]);
        }
        cout << ans << "\n";
    }
    return 0;
}

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

using namespace std;

int main() {
	while (1) {
		int n;
		int ans=SEISEKI;

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

		sort(a[0], a[n-1]);	//昇順

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

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(void){
    
    int n,gap,what;
    int a[1001];
    
    while (1){
        cin >> n ;
        if(n == 0 ) break;
        
        for(int i=0;i<n;i++) {
            cin >> a[i];
        }
        gap = abs(a[0]-a[1]);
        
        for(int i = 0; i<n;i++){
            for(int j = i+1;j<n;j++){
                what = abs(a[i]-a[j]);
                if(gap>= what) gap = what;
            }
        }
        cout << gap << endl;
    }
    
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#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(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N;
	while(cin >> N && N){
		vector<int32> x(N);
		REP(i, N) cin >> x[i];
		int32 res = INF;
		sort(all(x));
		REP(i, N-1) res = min(res, x[i+1]-x[i]);
		cout << res << endl;
	}
}

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

int main(){
  int n;
  int a[1000+10];
  while(cin >> n && n!=0){
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    int ans[1000+10];
    for(int i=0;i<n-1;i++){
      ans[i]=abs(a[i+1]-a[i]);
    }
    sort(ans,ans+n-1);
    cout << ans[0] << endl;
  }
  return 0;
}

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

int main(){
	while(1){	
	int n,s[100],sa=100,h;
	cin>>n;
	if(n==0) break;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<n-1;i++){
		for(int l=i+1;l<n;l++){
			h=s[l]-s[i];
			if(h<0) h=h*(-1);
			if(sa>=h) sa=h;
		}
	}
	cout<<sa<<endl;
	}	
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;

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