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++: 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);
        Rep(i, N) cin >> a[i];
        ll thismin = 1e10;
        Rep(i, N) {
            Rep(n, N) {
                if (n == i) continue;
                thismin = min(thismin, abs(a[i] - a[n]));
            }
        }
        ans.push_back(thismin);
        cin >> N;
    }
    Foreach(i, ans) out(i);
    return 0;
}

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

#define reps(i,j,k) for(int i=j;i<k;i++)
#define rep(i,j) reps(i,0,j)

using namespace std;

typedef vector<int> vi;

int main(){
	
	int n;
	while(cin >> n, n){
		vi v(n);
		rep(i, n) cin >> v[i];
		sort(v.begin(), v.end());
		int m = (1<<29);
		rep(i,n-1){
			m = min(m, v[i+1] - v[i]);
		}
		cout << m << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    while(1){
        int N;
        scanf("%d",&N);
        if(N==0)break;
        int a[1145];
        rep(i,N){
            scanf("%d",&a[i]);
        }
        sort(a,a+N);
        int ans=1145141919;
        rep(i,N-1){
            ans=min(ans,a[i+1]-a[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

using namespace std;

const int INF = 1e9 + 10;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<int> a(n);

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

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

    int ans = INF;
    
    for (int i = 0; i < n - 1; i++) {
      ans = min(ans, abs(a[i] - a[i + 1]));
    }

    cout << ans << endl;
    
    
  }
  
  return 0;
}