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 <string>
#include <vector>
#include <algorithm>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	while(cin >> n,n){
	vector<int> a(n);
	REP(i,n)cin >> a[i];
	sort(a.begin(),a.end());
	int min_ = 1e9;
	REP(i,n - 1)min_ = min(min_,abs(a[i] - a[i + 1]));
	cout << min_ << endl;
	}
  return 0;
}

C++: #pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
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; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {

    while (true) {
    
        ll n; cin >> n;
        if (!n) break;
        vector<ll> a(n); REP(i, n) cin >> a[i];

        sort(ALL_OF(a));

        ll mind = LINF;
        REP(i, n-1) {
            chmin(mind, a[i+1] - a[i]);
        }
        cout << mind << endl;

    }
    
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
    int n;
    cin >> n;
    
        if(n == 0){
            cout << endl;
            break;
        }
    vector<int> a(n);
    for(int i=0; i<n; i++)  cin >> a.at(i);
    
    sort(a.begin(),a.end());
    
    int min, d;
    min = 1000000;
    
    for(int i=0; i<n-1; i++){
        d = (a.at(i) - a.at(i+1) > 0 ? a.at(i)-a.at(i+1):a.at(i+1)-a.at(i));
        if(min > d) min = d;
    }
    
    cout << min << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
vector<int> v1;
int main(){
	int n;
	int a,b,c;
	while(cin>>n){
		if(!n)break;
		v1.clear();
		for(int i=0;i<n;i++){
			cin>>a;
			v1.push_back(a);
		}
		sort(v1.begin(),v1.end());
		b=1e9;
		for(int i=0;i<n-1;i++){
			a=v1[i+1]-v1[i];
			if(b>a)b=a;
		}
		cout<<b<<endl;
	}
}

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

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 mini = INT_MAX;
		int idx;
		for(int i=0;i<n-1;i++){
			mini = min(mini,abs(a[i]-a[i+1]));
		}
		cout << mini<<endl;
	}
	
	return 0;
}

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

using namespace std;

int main(void){
	while(1){
		int n; cin >> n;
		if(!n) break;

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

		sort(a, a+n);

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

		cout << ans << endl;
	}

}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	while(true){
		int N=read();
		if(N==0) break;
		int a[N];
		int minimum=100000000;
		REP(i,N){
			a[i]=read();
		}
		sort(a,a+N);
		REP(i,N-1){
			minimum = min(a[i+1]-a[i],minimum);
		}
		cout << minimum<<endl;
	}
}

C++: //https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Prelim/1608?year=2016

#include <bits/stdc++.h>

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());

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

        cout << ans << endl;
    }

    return 0;
}

/*
 *
 */

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

void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
void iput(int input) {put(input);}
void lput(long long input) {put(input);}

int main(){
  while(true){
    int n, in, prev, min, sa;
    vector<int> input;
    cin >> n;
    if(n != 0){
      for(int i=0; i<n; i++){
        cin >> in;
        input.push_back(in);
      }
      sort(input.begin(), input.end());
      for(int i=1; i<n; i++){
        sa = abs(input[i-1] - input[i]);
        if(i==1){
          min = sa;
        }else{
          min = min > sa ? sa : min;
        }
      }
      iput(min);
    }else{
      break;
    }
  }
}

C++: #include<stdio.h>

int main(void){
 int n,a[1001],i,j,b,c,min;

 while(1){
  scanf("%d",&n);
  min=1000000;

  if(n==0){
   break;
  }
  for(i=0;i<n;i++){
   scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++){
   for(j=n-1;j>i;j--){
    if(a[j-1]<a[j]){
     b=a[j-1];a[j-1]=a[j];a[j]=b;
    }
   }
  }
  for(i=0;i<n;i++){
   c=a[i]-a[i+1];
   if(min>c){
    min=c;
   }
  }
  printf("%d\n",min);
 }
}

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

using VI = vector<long>;

int main() {
  while (1) {
    long n;
    cin >> n;
    if (!n) {
      return 0;
    }
    VI v;
    for (int i = 0; i < n; i++) {
      long a;
      cin >> a;
      v.push_back(a);
    }
    sort(v.begin(), v.end());
    long diff = 1e9;
    for (int i = 1; i < n; i++) {
      diff = min(diff, v[i] - v[i - 1]);
    }
    cout << diff << endl;
  }
}

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

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

int n;
long long int a[1001];

int main(){
  while(cin>>n&&n){

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

    long long int ans = 1000001;

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