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 ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define sint(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;


typedef pair<int,int>P;

const int MAX_N = 100005;

int n;

int main()
{
    while(1){
        cin >> n;
        if(n == 0){
            break;
        }
        vector<int> vec(n);
        rep(i,n){
            cin >> vec[i];
        }
        int ans = INF;
        rep(i,n){
            for(int j = i+1;j<n;j++){
                ans = min(ans,abs(vec[i]-vec[j]));
            }
        }
        cout << ans << "\n";
    }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,i;
  int a[1001]={};
  while(1){
    int min = 1000001;
    cin >>n;
    if(n==0)break;
    for(i=0;i<n;++i){
      cin >>a[i];
    }
    sort(a,a+n);
    for(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<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    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 = 0; i < n-1; i++){
            ans = min(ans, a[i+1]-a[i]);
        }
        cout << ans << endl;
    }
}

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

int main() {
	int n;
	while (std::cin >> n && n) {
		std::vector<int> a;
		int minLength = INT_MAX;

		//????????????????????\???
		for (int i = 0; i < n; i++) {
			int b;
			std::cin >> b;
			a.push_back(b);
		}

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

		//????°???????????±???????
		for (int i = 0; i < a.size() - 1; i++) {
			minLength = std::min(a[i], a[i + 1]);
		}

		std::cout << minLength << std::endl;
	}
	return 0;
}

C++:     #include <bits/stdc++.h>
    #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 pb(a) push_back(a)
    #define INF 999999999999
    #define MOD 1000000007
    using namespace std;
    typedef long long LL;
    typedef pair<int, int> P;
    typedef pair<LL, LL> LP;
    typedef pair<int, P> PP;
    typedef pair<LL, LP> LPP;
    typedef vector<LL> LV;

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


    LL gcd(LL a, LL b){    return b != 0 ? gcd(b, a % b) : a;} 

    LL lcm(LL number1,LL number2){	return number1 * number2 / gcd(number1,number2);}

    int f(){
        int n;
        cin >> n;
        if(n==0) return 0;
        int ans = 1e9;
        vector<int> x(n);
        REP(i,n){
            cin >> x[i];
        }
        sort(x.begin(),x.end());
        REP(i,n-1){
            ans = min(abs(x[i+1]-x[i]),ans);
        }
        cout << ans << endl;

        return 1;

    }

    int main(){
        while(f());

        return 0;
    }

C++: #include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(void)
{
        int i,j,num,diff;
            
        while(1){
                int min = 1000000;
                cin >> num;
                if(num == 0){ 
                        break;
                }   
                    
                vector<int> data(num);
                for(i = 0; i < num; i++){
                        cin >> data[i];
                }   
                    
                for(i = 0; i < num - 1; i++){
                        for(j = i + 1; j < num; j++){
                                diff = abs(data[i] - data[j]);
                                if(diff <= min){
                                        min = diff;
                                }   
                        }   
                }   
                cout << min <<endl;
        }   
        return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        for (auto &ai: a) cin >> ai;
        sort(begin(a), end(a));
        int mi = INF;
        for (int i = 0; i + 1 < n; i++) mi = min(mi, a[i + 1] - a[i]);
        cout << mi << endl;
    }
    return 0;
}

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

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<int> v(n);
    rep(i, n) {
      cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    int ans = 1000000; 
    rep(i, n - 1) {
      ans = min(ans, v.at(i + 1) - v.at(i));
    }
    cout << ans << endl;
  }
}

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

int m,nmin,nmax,ans,gap;
int a[201];
int main(){
	while(1){
		cin >>m;
		if(m==0)break;
		for(int i=0;i<m;i++){
			cin >>a[i];
		}
		sort(a,a+(m));
		gap=1000001;
		for(int i=1;i<m;i++){
			if(a[i]-a[i-1]<=gap){
				gap=a[i]-a[i-1];
			}

		}
		cout << gap<<endl;
	}
	
}

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

using namespace std;
typedef long long ll;

int ar[1000];

int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++)cin >> ar[i];

		sort(ar, ar + n);

		int ans = 99999999;

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

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int A[1100];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    while(true){
        int N;
        std::cin >> N;
        if(!N){return 0;}
    
        for(int i=0;i<N;++i){
            std::cin >> A[i];
        }

        sort(A, A+N);

        int res = 1001001001;
        for(int i=0;i+1<N;++i){
            res = min(res, A[i+1] - A[i]);
        }

        std::cout << res << std::endl;
    }
}