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

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

int main()
{

	int n = 1;
	
	while (cin >> n) {
		int ans = 1000001;
		if (n == 0)
			break;
		int a[1000];
		for (int i = 0;i < n;i++) {
			cin >> a[i];
		}
		for (int i = 0;i < n - 1;i++) {
			for (int j = i + 1;j < n;j++) {
				if (ans > abs(a[i] - a[j]))
					ans = abs(a[i] - a[j]);
			}
		}
			cout << ans << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define PB push_back
#define MP make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    vi c;
    for (int i = 0; i < n; i++) {
      int tmp;
      cin >> tmp;
      c.PB(tmp);
    }
    sort(c.begin(), c.end());
    int ab = INF;
    for (int i = 1; i < n; i++) {
      if (abs(c[i]-c[i-1]) < ab) {
        ab = abs(c[i]-c[i-1]);
      }
    }
    cout << ab << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,a[1001]={};
  while(1){
    int min=1000000;
    cin>>n;
    if(n==0)break;

    for(int i=0;i<n;i++){
      cin>>a[i];
      if(i>0){
      for(int j=0;j<i;j++)
	  if(min>abs(a[i]-a[j]))min=abs(a[i]-a[j]);
      }
    }

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

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

int main(){
	int n,ans,x;
	vector<int> vec;
	while(1){
		cin >> n;
		if(n == 0)break;
		ans = 10000000;
		vec.clear();
		for(int i = 0;i < n;i++){
			cin >> x;
			vec.push_back(x);
		}
		sort(vec.begin(),vec.end());
		for(int i = 1;i < n;i++){
			ans = min(ans,vec[i] - vec[i-1]);
		}
		cout << ans <<endl;
	}
	return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	vector<int> a(n); rep(i, 0, n) { cin >> a[i]; }
	sort(a.begin(), a.end());
	int ans = INF;
	rep(i, 1, a.size()) {
		ans = min(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,n){
    int a[n],d=1<<30;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=1;i<n;i++)d=min(d,a[i]-a[i-1]);
    cout<<d<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

int N;
int a[1000];

int main() {
	while (cin >> N, N) {
		REP(i, N) scanf("%d", a + i);
		sort(a, a + N);
		
		int ans = INF;
		REP(i, N - 1) chmin(ans, a[i + 1] - a[i]);
		if (debug) printf("@ ");
		cout << ans << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n,temp;
	while(1){
		cin >> n;
		if(n==0) break;
		int a[n],sa[n-1],min=1000000;
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(a[i]>a[j]){
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}
		for(int i=1;i<n;i++){
			if(a[i]>a[i-1]){
				sa[i]=a[i]-a[i-1];
			}else{
				sa[i]=a[i-1]-a[i];
			}
			if(min>sa[i]){
				min=sa[i];
			}
		}
		cout << min << endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n;
int a[100000];

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

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

using namespace std;

int main(void) {
    int times;
    while (1) {
        cin >> times;
        if (times == 0) {
            break;
        }
        int min = 1e09;
        vector<int> v(times);
        for (int i = 0; i < times; i++) {
            cin >> v[i];
        } 
        sort(v.begin(), v.end());
        for (int i = 0; i < times - 1; i++) {
            if (v[i + 1] - v[i] < min) {
                min = v[i + 1] - v[i];
            }
        } 
        cout << min << endl;
    } 

    return 0;
}

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<iostream>
#include<algorithm>
using namespace std;
const int MAX_N=1e3*5;
const int INF=1e8;
int a[MAX_N];
int main(){
	int n;
	while(cin>>n && n!=0){
		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;
	}
}