Skip to content

Instantly share code, notes, and snippets.

@orian
Created June 27, 2013 11:42
Show Gist options
  • Save orian/5875825 to your computer and use it in GitHub Desktop.
Save orian/5875825 to your computer and use it in GitHub Desktop.
simple script to generate 31 possible loops in Dart (http://dartlang.org)
#!/usr/bin/python
from string import Template
import itertools
def GenerateOne(name, initializer, test, update, use_break, use_continue):
if not test and not use_break:
return
tmpl = Template("""
$name() {
$before_loop for ($init; $test; $update) {
$loop }$after_loop
}
""")
def_values = {
'name': name,
'before_loop': '',
'init': '',
'test': '',
'update': '',
'loop': '',
'after_loop': ''
}
# i must be initialized in or before loop
if initializer:
def_values['init'] = 'var i = 0'
else:
def_values['before_loop'] = ' var i = 0\n'
if test:
def_values['test'] = 'i < 5'
if use_break:
def_values['loop'] += ''' if (i > 3) {
break;
}\n'''
if update:
def_values['update'] = '++i'
else:
def_values['loop'] += ' ++i;\n'
if use_continue:
def_values['loop'] += ''' if (i>2) {
continue;
}\n'''
print(tmpl.substitute(def_values))
def GenerateAll():
num = 0
for vals in itertools.product([True, False], repeat=5):
GenerateOne('f_%s' % num, *vals)
num+=1
if __name__ == '__main__':
GenerateAll()
f_0() {
for (var i = 0; i < 5; ++i) {
if (i > 3) {
break;
}
if (i>2) {
continue;
}
}
}
f_1() {
for (var i = 0; i < 5; ++i) {
if (i > 3) {
break;
}
}
}
f_2() {
for (var i = 0; i < 5; ++i) {
if (i>2) {
continue;
}
}
}
f_3() {
for (var i = 0; i < 5; ++i) {
}
}
f_4() {
for (var i = 0; i < 5; ) {
if (i > 3) {
break;
}
++i;
if (i>2) {
continue;
}
}
}
f_5() {
for (var i = 0; i < 5; ) {
if (i > 3) {
break;
}
++i;
}
}
f_6() {
for (var i = 0; i < 5; ) {
++i;
if (i>2) {
continue;
}
}
}
f_7() {
for (var i = 0; i < 5; ) {
++i;
}
}
f_8() {
for (var i = 0; ; ++i) {
if (i > 3) {
break;
}
if (i>2) {
continue;
}
}
}
f_9() {
for (var i = 0; ; ++i) {
if (i > 3) {
break;
}
}
}
f_12() {
for (var i = 0; ; ) {
if (i > 3) {
break;
}
++i;
if (i>2) {
continue;
}
}
}
f_13() {
for (var i = 0; ; ) {
if (i > 3) {
break;
}
++i;
}
}
f_16() {
var i = 0
for (; i < 5; ++i) {
if (i > 3) {
break;
}
if (i>2) {
continue;
}
}
}
f_17() {
var i = 0
for (; i < 5; ++i) {
if (i > 3) {
break;
}
}
}
f_18() {
var i = 0
for (; i < 5; ++i) {
if (i>2) {
continue;
}
}
}
f_19() {
var i = 0
for (; i < 5; ++i) {
}
}
f_20() {
var i = 0
for (; i < 5; ) {
if (i > 3) {
break;
}
++i;
if (i>2) {
continue;
}
}
}
f_21() {
var i = 0
for (; i < 5; ) {
if (i > 3) {
break;
}
++i;
}
}
f_22() {
var i = 0
for (; i < 5; ) {
++i;
if (i>2) {
continue;
}
}
}
f_23() {
var i = 0
for (; i < 5; ) {
++i;
}
}
f_24() {
var i = 0
for (; ; ++i) {
if (i > 3) {
break;
}
if (i>2) {
continue;
}
}
}
f_25() {
var i = 0
for (; ; ++i) {
if (i > 3) {
break;
}
}
}
f_28() {
var i = 0
for (; ; ) {
if (i > 3) {
break;
}
++i;
if (i>2) {
continue;
}
}
}
f_29() {
var i = 0
for (; ; ) {
if (i > 3) {
break;
}
++i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment