Remove while loop and readd c-style for loops i.e. all loops are just for

This commit is contained in:
Ginger Bill
2017-01-27 17:43:42 +00:00
parent 832009f33a
commit 92453369c5
11 changed files with 201 additions and 139 deletions

View File

@@ -168,25 +168,25 @@ special_expressions :: proc() {
loops :: proc() {
// while loops
while true {
// The C-style for loop
for i := 0; i < 123; i += 1 {
break;
}
while x := 123; x < 124 {
x += 2;
for i := 0; i < 123; {
break;
}
for false {
break;
}
for {
break;
}
/*
This only C-style for loop has now been removed
for i := 0; i < 123; i += 1 {
}
*/
for i in 0..<123 {
for i in 0..<123 { // 123 exclusive
}
for i in 0..122 {
for i in 0..122 { // 122 inclusive
}
for val, idx in 12..<16 {
@@ -214,26 +214,15 @@ loops :: proc() {
}
when false {
while i := 0; i < name.count {
r, size := utf8.decode_rune(name[i:]);
i += size;
for i, size := 0; i < name.count; i += size {
r: rune;
r, size = utf8.decode_rune(name[i:]);
fmt.printf("%r\n", r);
}
}
// Emulate a C-style loop (not exactly the same though)
while x := 0; x < 10 {
defer x += 2;
/* rest of the code */
// If `break` is used, the `defer` is still called so it's not the same
// as a C-style for loop
}
procedure_overloading();
}