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>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(a,b) (0<=(a)&&(a)<(b))

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int A[1001];
		int ans=1000100;
		REP(i,0,n) cin>>A[i];
		sort(A,A+n);
		REP(i,1,n)	ans=min(ans,abs(A[i]-A[i-1]));
		p(ans);
	}
	return 0;
}

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

void bubbleSort( int* a, int n )
{
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
        {
            if( a[j] < a[j-1] )
            {
                int t = a[j];
                a[j] = a[j-1];
                a[j-1] = t;
            }
        }
}

int main()
{
    int n, a[1000];

    while( cin >> n )
    {
        if( !n )
            break;

        for( int i = 0; i < n; i++ )
            cin >> a[i];

        bubbleSort( a, n );

        int min = 1000000000;
        for( int i = 0; i < n - 1; i++ )
            if( a[i+1] - a[i] < min )
                min = a[i+1] - a[i];

        cout << min << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
int students[1001];

int main()
{
    int n, mindiff;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) scanf("%d", &students[i]);
        sort(students, students+n);
        mindiff = 1000001;
        for (int i = 1; i < n; i++) {
            mindiff = min(mindiff, students[i] - students[i-1]);
            if (mindiff == 0) break;
        }
        printf("%d\n", mindiff);
    }
    return 0;
}

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

using namespace std;

int main(){

    int long long n;
    while(true){
        cin>>n;
        if(n==0)break;
        int long long st[n];
        int long long sa[n-1];

        for(int long long i=0;i<n;i++){
            cin>>st[i];
        }
        sort(st,st+n);

        for(int long long i=1;i<n;i++){
            sa[i-1]=st[i]-st[i-1];
        }
        sort(sa,sa+n-1);
        cout<<sa[0]<<endl;
    }
return 0;




}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long
 
	
 
 
int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        vector<ll> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        ll ans = a[1]-a[0];
        for(int i=2;i<n;i++){
            if(ans>a[i]-a[i-1]){
                ans = a[i]-a[i-1];
            }
        }
        cout<<ans<<endl;
    }
}

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

using namespace std;

int n[1000]={};
int a[1000][1000]={};
int ans = 1000000;

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("%d",&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 = 100000;
    }
    

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#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 vi vector<int>
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

const int MOD = 1e9 + 7;
const int INF = 1 << 30;


class UnionFind{
private:
        vector<int> par,rank,sizes;
        int tree;

public:
        explicit UnionFind(const int n) : tree(n){
            par.resize(n+1);
            rank.resize(n+1);
            sizes.resize(n+1);
            rep(i,n){
                par[i] = i;
                sizes[i] = 1;
            }
        }

        ~UnionFind() = default;

        int root(int x){
            if(par[x] == x) return x;
            else return par[x] = root(par[x]);
        }

        int find(int x){ return root(x);}

        void unite(int x, int y) {
            x = root(x);
            y = root(y);
            if (x == y) return;

            if (rank[x] < rank[y]) swap(x, y);
            par[y] = x;
            tree--;
            sizes[x] += sizes[y];
            if (rank[x] == rank[y]) rank[x]++;
        }

        bool same(int x, int y){
            return root(x) == root(y);
        }

        int size(int x){
            return sizes[x];
        }

        int sumTree(){
            return tree;
        }
};

template <typename T>
class segmentTree{
private:
    int n;
    vector<T> arr;
public:

    explicit segmentTree(vector<T> v){
        ll sz = v.size();
        //while()

        arr.resize(2*n - 1);

    }

    T &operator[](int n){ return arr[n];}


};

template <int mod>
class ModInt{
private:
    ll _num;

public:
    ModInt(){_num = 0;}
    explicit ModInt(ll value){_num = value%mod;}

    ModInt operator+(ModInt &x){ return ModInt(_num + x._num);}
    ModInt operator-(ModInt &x){ return ModInt(_num - x._num);}
    ModInt operator*(ModInt &x){ return ModInt(_num * x._num);}
    friend ostream &operator<<(ostream &os, const ModInt &x){os<<x._num; return os;}
    friend istream &operator>>(istream &is, ModInt &x){is>>x._num; return is;}
};
using mint = ModInt<MOD>;


class topos{

};

int gcd(int a,int b){
    return b ? gcd(b,a%b) : a;
}


int main() {
    while(true){
        int n; cin >> n;
        if(n == 0) break;

        vi a(n);
        rep(i,n) cin >> a[i];

        sort(a.begin(),a.end());

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

}

C++: #include <iostream>
#include <algorithm>
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];
         }

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

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

}