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++: #pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
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; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {

    while (true) {
    
        ll n; cin >> n;
        if (!n) break;
        vector<ll> a(n); REP(i, n) cin >> a[i];

        sort(ALL_OF(a));

        ll mind = LINF;
        REP(i, n-1) {
            chmin(mind, a[i+1] - a[i]);
        }
        cout << mind << endl;

    }
    
}

C++: 

using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>/*
#define out(S) cout<<(S)<<endl;
#define mod(i) ((i)%(ll)(1000000000 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define For(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFor(i,a,b) for(size_t i=(a)-1;i>=(b);i--)
#define Rep(i,a) for(size_t i=0;i<(a);i++)
#define rRep(i,a) for(size_t i=(a)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)*/

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;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
    int n;
    while(scanf("%d",&n),n) {
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        int ans=1<<30;
        for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) {
            ans=min(ans,abs(a[i]-a[j]));
        }
        printf("%d\n",ans);
    }
}

C++: #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

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

int main(){
	int n;

	while(cin >> n, n){
		vector<LL> a;
		REP(i, n){
			LL n;
			cin >> n;
			a.pb(n);
		}
		sort(a.begin(), a.end());

		LL ans = INF;

		REP(i, n - 1){
			if(abs(a[i] - a[i + 1]) < ans) {
				ans = abs(a[i] - a[i + 1]);
			}
		}

		cout << ans << endl;
	}
}

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

using namespace std;

int main(){
	
	
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		int p[n];
		for(int i=0;i<n;i++) cin >> p[i];
		
		sort(p,p+n);
		
		int dif,ma=10000000;
		for(int i=0;i<n-1;i++){
			dif=p[i+1]-p[i];
			ma=min(dif,ma);
		}
		cout << ma <<endl;
	}
	
	
	
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    while(cin >> n, n){
        vector<int> a(n);
        rep(i, 0, n) cin >> a[i];
        sort(all(a));
        int MIN = 1e9;
        rep(i, 0, n - 1){
            MIN = min(MIN, a[i + 1] - a[i]);
        }
        cout << MIN << endl;
    }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int n;
    int a[1001];
    int ans;

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

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

        int min = 1000000;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i != j){
                    ans = abs(a[i] - a[j]);
                    if(ans < min) min = ans;
                }
            }
        }
        cout << min << endl;
    }
}

C++: #include <bits/stdc++.h>
 
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long int ll;
using namespace std;

int main(void) {
    int n;
    vector<int> a;
    while(cin >> n && n) {
        a.resize(n);
        REP(i, n) cin >> a[i];
        int ans = numeric_limits<int>::max();
        sort(a.begin(), a.end());
        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(){
    int n,dif;
    while(cin>>n){
if(n==0)break;
        dif=1000000;
        int a[1000];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
     sort(a,a+n);
for(int i=0;i<n-1;i++)
        if(max(a[i]-a[i+1], a[i+1]-a[i])<dif)dif=max(a[i]-a[i+1], a[i+1]-a[i]);

cout<<dif<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdlib>
using namespace std;
int main(){
  while(true){
    int n;
    cin >> n;
    if(n==0)
      break;
    int a[1000];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    int dif = 1000001;
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        int d=abs(a[i]-a[j]);
        if(d<dif){
          dif=d;
        }
      }
    }
    cout << dif << endl;
  }
  return 0;
}