#!/usr/bin/env python
# -*- coding: utf-8 -*-
i = 1
while i<= 1024:
    print i
    i *= 2
else:
    print "else"

执行结果:

% python gramma/while.py                                                    ✭
1
2
4
8
16
32
64
128
256
512
1024
else