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 <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)	for(ll i=(a); i<(b); i++)
#define REP(i,n)	FOR(i,0,(n))
typedef pair< ll, ll >	cp2;
typedef pair< ll, cp2 >	cp3;
const ll mod = 1000000007;
bool debug = false;


int N;
int A[1123];
int ans;

int main(){
	
	while( cin>>N, N ){
		ans = mod;
		REP( i, N ) cin>>A[i];
		sort( A, A+N );
		REP( i, N-1 ) ans = min( ans, A[i+1]-A[i] );
		if( debug ) cout<<"@ ";
		cout<<ans<<endl;
	}
	
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#define SEISEKI 1000001

using namespace std;

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

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

		sort(a.begin(), a.end());	//昇順

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

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

int main(){
  int n,a[1000],minx=1000000,i;
  cin >> n;
  while(n!=0){
    minx=1000000;
    for(i=0;i<n;i++)
      cin >> a[i];
    sort(a,a+n);
    for(i=0;i<n-1;i++)
      if(minx>a[i+1]-a[i])
        minx=a[i+1]-a[i];
    cout << minx << endl;
    cin >> n;
  }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int a[1001];
    int n;
    while(cin >> n){
        if(n == 0)  break;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        int min = 10000001;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if(fabs(a[i]-a[j]) < min){
                    min = fabs(a[i]-a[j]);
                }
            }
        }
        cout << min << endl;
    }
    
    return 0;
}

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

using namespace std;

int main(){
 int n;
 while(1){
  cin >> n;
  if(n==0)break;
  long long a[n],i,ans=1e7;
  for(i=0;i<n;i++)cin >> a[i];
  sort(a,a+n);
  for(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;

#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    int a[1000];
    lpin(a,i,n);
    int ans=1000001,b;
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	if(a[i]>a[j]) b=a[i]-a[j];
	else b=a[j]-a[i];
	if(ans>b) ans=b;
      }
      if(b==0) break;
    }
    cout<<ans<<endl;
  }
  
  return 0;
}