aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-08-26 13:54:35 +0100
committergingerBill <bill@gingerbill.org>2019-08-26 13:54:35 +0100
commit01c10aa9447d135bdda5dc25583a5e1f94cbda6d (patch)
tree10f37633b1cf71e8dcb29afb3418220e71daf733 /examples
parent4908d1ebdd00a8822d9ef59245f2456db4b6dbfc (diff)
`inline for` loops (only for 'in' based for loops)
Diffstat (limited to 'examples')
-rw-r--r--examples/demo/demo.odin39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin
index a96056b61..cef814a56 100644
--- a/examples/demo/demo.odin
+++ b/examples/demo/demo.odin
@@ -1018,6 +1018,44 @@ quaternions :: proc() {
fmt.println(c);
fmt.println(q);
}
+ { // Memory layout of Quaternions
+ q := 1 + 2i + 3j + 4k;
+ a := transmute([4]f64)q;
+ fmt.println("Quaternion memory layout: xyzw/(ijkr)");
+ fmt.println(q); // 1.000+2.000i+3.000j+4.000k
+ fmt.println(a); // [2.000, 3.000, 4.000, 1.000]
+ }
+}
+
+inline_for_statement :: proc() {
+ fmt.println("\n#inline for statements");
+
+ fmt.println("Ranges");
+ inline for x, i in 1..<4 {
+ fmt.println(x, i);
+ }
+
+ fmt.println("Strings");
+ inline for r, i in "Hello, 世界" {
+ fmt.println(r, i);
+ }
+
+ fmt.println("Arrays");
+ inline for elem, idx in ([4]int{1, 4, 9, 16}) {
+ fmt.println(elem, idx);
+ }
+
+
+ Foo_Enum :: enum {
+ A = 1,
+ B,
+ C = 6,
+ D,
+ }
+ fmt.println("Enum types");
+ inline for elem, idx in Foo_Enum {
+ fmt.println(elem, idx);
+ }
}
main :: proc() {
@@ -1040,5 +1078,6 @@ main :: proc() {
deferred_procedure_associations();
reflection();
quaternions();
+ inline_for_statement();
}
}