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 <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n;
  while (cin >> n, n)
  {
    vector<int> a(n);
    for (auto &e : a)
      cin >> e;
    sort(a.begin(), a.end());
    int ans = 1e9;
    for (int i = 0; i < n - 1; ++i)
      ans = min(ans, abs(a[i] - a[i + 1]));
    cout << ans << endl;
  }

  return 0;
}

C++: //
//  main.cpp
//  Selection of Participants of an Experiment
//
//  Created by x15071xx on 2017/06/13.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[]) {
    
   
    while (1) {
        
        int n,i,min=10000000,tmp;
        vector<int> s;
        
        
        cin >> n;
        
        if (n == 0) {
            break;
        }
        
        for (i = 0; i < n; i++) {
            cin >> tmp;
            s.push_back(tmp);
        }
        
        sort(s.begin(), s.end());
        
        for (i = 0; i < s.size()-1; i++) {
            int ans = abs(s[i] - s[i+1]);
            
            if (ans < min) {
                min = ans;
            }
        }
        
        cout << min << endl;
        
    }
    return 0;
}

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

vector<int> ans;

int main(){
  int n;

  while(cin >> n,n){
    vector<int> val;
    int ans_t=1000;
    for(int i=0; i<n; ++i){
      int tmp;
      cin >> tmp;
      val.push_back(tmp);
    }
    sort(val.begin(),val.end(),greater<int>());
    for(int i=0; i<n; ++i){
      int tmp = val[i]-val[i+1];
      if(ans_t > tmp){
	ans_t = tmp;
      }
    }
    ans.push_back(ans_t);
  }

  for(auto i:ans){
    cout << i << endl;
  }
  return 0;
}

C++: #include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        vector<int> a(n);
        rep(i, n) cin >> a[i];

        int ans = INF;
        rep(i, n){
            rep(j, n){
                if(i == j){
                    continue;
                }

                int tmp = abs(a[i] - a[j]);
                if(tmp < ans){
                    ans = tmp;
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

int n, buf;
vector<int> v, dif;

void solve() {
  sort(v.begin(), v.end());
  for(int i = 1; i < n; ++i) {
    dif.push_back(v[i] - v[i - 1]);
  }
  cout << *min_element(dif.begin(), dif.end()) << endl;
  dif.clear();
}

int main() {
  while(cin >> n && n) {
    for(int i = 0; i < n; ++i) {
      cin >> buf;
      v.push_back(buf);
    }
    solve();
    v.clear();
  }
  return 0;
}

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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

using namespace std;

int solve(int N) {
	vector<int> v(N);
	rep(i, N) cin >> v[i];
	sort(all(v));
	int res = INT_MAX;
	reps(i, 1, N) {
		chmin(res, abs(v[i-1] - v[i]));
	}
	return res;
}

signed main() {
	int N;
	while (cin >> N, N) cout << solve(N) << endl;
}

C++: #include<bits/stdc++.h>
#define INF (1e9)
#define N 1005
using namespace std;

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

C++: #include <bits/stdc++.h>
using namespace std;

int main(void){
	int n;
	while(true){
		cin >> n;
		if(!n) break;
		vector<int> a(n);
		for(int i = 0; i < n; ++i){
			cin >> a[i];
		}
		sort(a.begin(), a.end());
		int ans = a[1] - a[0];
		for(int i = 0; i < n-1; ++i){
			ans = min(ans, a[i+1] - a[i]);
		}
		cout << ans << endl;
	}
	return 0;
}