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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF INT_MAX

int a[2000];

int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(n == 0)
            break;
        REP(i,n)
            scanf("%d",&a[i]);
       
        int min = INF; 
        for(int i = 0;i < n;i++){
            for(int j = i + 1;j < n;j++){
                if(min > abs(a[i] - a[j]))
                    min = abs(a[i] - a[j]);
            }
        }
        printf("%d\n",min);
    }
    return 0;
}

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

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		int mDistance = 1000000;
		int data[1000000] = {0};
		for(int i = 0; i < n; i++){
			int a = 0;
			cin >> a;
			if(data[a] == 1){
				mDistance = 0;
			}
			data[a] = 1;
			if(mDistance != 0 && i >= 1){
			for(int j = 1; a + j < 1000000 && j <= mDistance; j++){
				if(data[a + j] == 1){
					mDistance = j;
					break;
				}
			}
			for(int j = 1; a - j >= 0 && j <= mDistance; j++){
				if(data[a - j] == 1){
					mDistance = j;
					break;
				}
			}
			}
		}
		cout << mDistance << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

const int INF=1000000;

int N;
int temp;
int ans;
vector<int> student;

int main() {
	while(true){
		//?????????
		ans=INF;
		while(student.size()>0)student.pop_back();


		cin>>N;
		if(N==0)break;

		for (int i = 0; i < N; i++) {
			cin>>temp;
			student.push_back(temp);
		}
		sort(student.begin(),student.end());
		for (int i = 0; i < N - 1; i++) {
			ans=min(ans,student[i+1]-student[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		int mDistance = 1000000;
		int data[1000000] = {0};
		for(int i = 0; i < n; i++){
			int a = 0;
			cin >> a;
			if(data[a] == 1){
				mDistance = 0;
			}
			data[a] = 1;
			for(int j = 1; i + j < 1000000 && j <= mDistance; j++){
				if(data[i + j] == 1){
					mDistance = j;
					break;
				}
			}
			for(int j = 1; i - j >= 0 && j <= mDistance; j++){
				if(data[i - j] == 1){
					mDistance = j;
					break;
				}
			}
		}
		cout << mDistance << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include<iostream>
#include<unordered_set>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
//#define printe(...) void();
#define printE(...) fprintf(stderr, __VA_ARGS__);
//#define printE(...) void();


#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,P) scanf("%d %d %d %d",&n,&m,&o,&P)
#define SINT5(n,m,o,P,q) scanf("%d %d %d %d %d",&n,&m,&o,&P,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 1'010'000'000; // 0x3C33'6080
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second

int bitCount(unsigned int bits) {
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);    //  2bitごとに計算
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);    //  4bitごとに計算
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);    //  8bitごとに計算
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);    //  16ビットごとに計算   
	return (bits & 0x0000ffff) + (bits >> 16);    //  32ビット分を計算   
}




int a[1003];

int main() {
	int n;
	while (cin >> n, n) {
		rep(i, n) cin >> a[i];
		sort(a, a + n);

		int ret = 1000000009;
		rep(i, n - 1) ret = min(ret, a[i + 1] - a[i]);
		cout << ret << endl;
	}

}

C++: 
using namespace std;
typedef long long ll;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>

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