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>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int a[1010];

int main(){
	while(1){
		cin>>n;
		if(n==0)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 n;
vector<int> a;
vector<int> s;
int main(){
  int i,j,min=10000000;
  while(1){
    cin >> n;
    if(n==0)break;
    min =10000000;
    for(i=0;i<n;i++){
      cin >> j;
      a.push_back(j);
    }
    sort(a.begin(),a.end());
    for(i=0;i<n-1;i++)if(min>a[i+1]-a[i])min = a[i+1]-a[i];
    cout << min << endl;
    while(a.size())a.pop_back();
  }
  return 0;
}

C++: #include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
  int i, j, tmp; 
  int number[1000]; 
  int n=0; 
  while(1){
  int min=1000000;
  scanf("%d", &n);
  if(n==0) {
      break;
  }
  for (i=0; i<n; i++){ 
    scanf("%d", &number[i]);
    }
  for (i=0; i<n-1; i++) { 
    for (j=i+1; j<n; j++) { 
        if(number[i]>number[j]){
        tmp =  number[i]; 
        number[i] = number[j]; 
        number[j] = tmp; 
        } 
    }
  }
  for(i=0;i<(n-1);i++){
      if(number[i+1]-number[i]<min){
          min=number[i+1]-number[i];
      }
  }
  cout<<min<<endl;
 }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define rep(i, n) for(int i = 0;i < n;i++)
#define reprb(i, n) for(int i = n;i >= 0;i--)
#define reps(i, m, n) for(int i = m;i < n;i++)
#define repsb(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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
vector<int> a;

int main(int argc,char * argv[])
{
	int n,in,mi=0;
	while(true)
	{
		cin>>n;

		if(n==0)	break;
		rep(i,n){
			cin>>in;
			a.pb(in);
			mi=max(mi,in);
		}
		rep(i,n){
			rep(j,n){
				if(i!=j)	mi=min(mi,abs(a[i]-a[j]));
			}
		}
		cout<<mi<<endl;
		a.clear();
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,a[1000],i,mn;
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	scanf("%d",&a[i]);
		sort(a,a+n);
		mn=a[1]-a[0];
		for(i=2;i<n;i++)	{
			mn=min(mn,a[i]-a[i-1]);
		}
		printf("%d\n",mn);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
//#define SEISEKI 10000000

using namespace std;

int main() {
	while (1) {
		int n;
		//int ans=SEISEKI;

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

		int ans = a[1] - a[0];

		sort(a, a+n);	//昇順

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

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

int main() {
	
	int n;
	int a[1100];
	int point[51000]; //データセットごとの点数
	int count = 0;
	
	while (1)
	{
		count++;
		
		cin >> n;
		
		if(n == 0) break; // 0を入力されたら終了
		
		for (int i = 0; i < n; i++) cin >> a[i];
		
		sort(a, a+n, greater<int>());
		
		int proa;
		int d;
		//データセットごとの作業
		for (int i = 0; i < n; i++) {
			
			// 隣のデータとの差
			d = abs(proa - a[i]);
			
			// 初期値は最大点
			if(i == 0) point[count - 1] = a[0];
			
			if(d < point[count - 1]) point[count - 1] = d;
			
			proa = a[i];
		}
	}
	
	for (int i = 0; i < count - 1; i++) {
		cout << point[i] << endl;
	}
	
	return 0;
}

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
while(1){
    ll n;
    cin>>n;
    if(n==0)return 0;
    V<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(all(a));
    int ans=INT_MAX;
    for(int i=0;i<n-1;i++){
       chmin(ans,a[i+1]-a[i]);
    }
    cout<<ans<<endl;
  }
}

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

using namespace std;

int main () {
  int n;
  while (cin >> n, n) {
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    int min_ = 10000;
    for (int i = 0; i < n - 1; i++) {
      min_ = min(min_, v[i + 1] - v[i]);
    }
    cout << min_ << endl;
  }
  
  return 0;
  
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

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

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

#define check abs(vec[i] - vec[i + 1])

int main() {
	int n, num_abs; vector<int> vec;
	while (1) {
		cin >> n; if (n == 0) break;
		num_abs = INT_MAX; vec.resize(n);
		for (int i = 0; i < n; i++) cin >> vec[i];
		sort(vec.begin(), vec.end());
		for (int i = 0; i < n - 1; i++){
			if (check < num_abs) num_abs = check;
			if (check == 0) { num_abs = check; break; }
		}
		cout << num_abs << endl;
		for (int i = 0; i < n; i++) vec.pop_back();
	}
	return 0;
}