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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	while (N != 0) {
		vi A(N);
		REP(i, N) {
			cin >> A[i];
		}
		so(A);
		int ans = INF;
		REP(i, N - 1) {
			chmin(ans, A[i + 1] - A[i]);
		}
		cout << ans << endl;
		cin >> N;
	}
	return 0;
}

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

using namespace std;

int main(void) {
    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 ans = 1e9;
        for (int i = 1; i < n; i++)
            ans = min(ans, a[i] - a[i - 1]);
        
        cout << ans << endl;
    }

    return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)

int n, a[1005], ans;

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

    while (cin >> n, n) {
        ans = (int)1e9 + 7;
        rep(i,n) cin >> a[i];
        rep(i,n) {
            for (int j = i+1; j < n; ++j) {
                if (ans > abs(a[i] - a[j])) ans = abs(a[i] - a[j]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
  int n;
  while(cin >> n,n){
    int a[n];
    for(int i=0; i<n; ++i){
      cin >> a[i];
    }
    int ans = 1000000;
    for(int i=0; i<n; ++i){
      for(int j=i+1; j<n; ++j){
        if(abs(a[i]-a[j]) < ans){
          ans = abs(a[i]-a[j]);
        }
      }
    }
    cout << ans << endl;
  }
}

C++: #include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{

	int n = 1;
	
	while (cin >> n) {
		int ans = 1000001;
		if (n == 0)
			break;
		int a[1000];
		for (int i = 0;i < n;i++) {
			cin >> a[i];
		}
		for (int i = 0;i < n - 1;i++) {
			for (int j = i + 1;j < n;j++) {
				if (ans > abs(a[i] - a[j]))
					ans = abs(a[i] - a[j]);
			}
		}
			cout << ans << endl;

	}
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
int a[1111];

int main(){
	cin.sync_with_stdio(false);
  while(cin>>n){
    if(n==0)break;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    int gap=INF;
    rep(i,n-1){
      if(gap>a[i+1]-a[i]){
        gap=a[i+1]-a[i];
      }
    }
    cout<<gap<<endl;
  }
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    while (1) {
        cin >> N;
        if (!N) break;
        vector<int> a(N);
        for (int i = 0; i < N; i++) {
            cin >> a[i];
        }
        int ans = 10000000;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                ans = min(ans, abs(a[i] - a[j]));   
            }
        }
        cout << ans << endl;
    }
}

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 s=1000001;
		for(int i=0;i<n;i++){
			for(int j=0;j<n-1;j++){
				if(s>abs(a[i]-a[j])){
					s=abs(a[i]-a[j]);
				}
			}
		}
		cout<<s<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	while(cin>>n,n){
		vi in(n);
		rep(i,n)cin>>in[i];
		int mi=inf;
		rep(i,n)rep(j,n)if(i!=j)mi=min(mi,abs(in[i]-in[j]));
		cout<<mi<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1000000000000000LL
#define rep(i,n) for(i=0;i<n;i++)

typedef pair<int,int> pii;
int i,j;


int main() {
    while(1){
        ll n;
        cin>>n;
        if(n==0)break;
        ll a[10000]={};
        rep(i,n)
            cin>>a[i];
        sort(a,a+n);
        ll m=INF;
        rep(i,n-1)
            m=min(m,abs(a[i]-a[i+1]));
        cout<<m<<endl;
    }
    return 0;
}