-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
126 additions
and
68 deletions.
There are no files selected for viewing
12 changes: 8 additions & 4 deletions
12
code-samples/control-structures-conditionals-expression-implicit-none.pony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
var x: (String | None) = | ||
if friendly then | ||
"Hello" | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
let friendly = false | ||
var x: (String | None) = | ||
if friendly then | ||
"Hello" | ||
end | ||
env.out.print(x.string()) |
16 changes: 10 additions & 6 deletions
16
code-samples/control-structures-conditionals-expression-union-type.pony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
var x: (String | Bool) = | ||
if friendly then | ||
"Hello" | ||
else | ||
false | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
let friendly = false | ||
var x: (String | Bool) = | ||
if friendly then | ||
"Hello" | ||
else | ||
false | ||
end | ||
env.out.print(x.string()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
x = 1 + if lots then 100 else 2 end | ||
actor Main | ||
new create(env: Env) => | ||
let lots = true | ||
var x: U32 | ||
x = 1 + if lots then 100 else 2 end | ||
env.out.print("x = " + x.string() + "—that's " + (if lots then "lots" else "not a lot" end)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
if a > b then | ||
env.out.print("a is bigger") | ||
else | ||
env.out.print("a is not bigger") | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
let a: U8 = 1 | ||
let b: U8 = 2 | ||
if a > b then | ||
env.out.print("a is bigger") | ||
else | ||
env.out.print("a is not bigger") | ||
end |
18 changes: 11 additions & 7 deletions
18
code-samples/control-structures-conditionals-if-elseif-else.pony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
if a == b then | ||
env.out.print("they are the same") | ||
elseif a > b then | ||
env.out.print("a is bigger") | ||
else | ||
env.out.print("b bigger") | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
let a: U8 = 2 | ||
let b: U8 = 1 | ||
if a == b then | ||
env.out.print("they are the same") | ||
elseif a > b then | ||
env.out.print("a is bigger") | ||
else | ||
env.out.print("b bigger") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
if a > b then | ||
env.out.print("a is bigger") | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
let a: U8 = 2 | ||
let b: U8 = 1 | ||
if a > b then | ||
env.out.print("a is bigger") | ||
end |
22 changes: 13 additions & 9 deletions
22
code-samples/control-structures-conditionals-nested-if-else.pony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
if a == b then | ||
env.out.print("they are the same") | ||
else | ||
if a > b then | ||
env.out.print("a is bigger") | ||
else | ||
env.out.print("b bigger") | ||
end | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
let a: U8 = 2 | ||
let b: U8 = 2 | ||
if a == b then | ||
env.out.print("they are the same") | ||
else | ||
if a > b then | ||
env.out.print("a is bigger") | ||
else | ||
env.out.print("b bigger") | ||
end | ||
end |
14 changes: 9 additions & 5 deletions
14
code-samples/control-structures-loops-for-while-comparison.pony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
let iterator = ["Bob"; "Fred"; "Sarah"].values() | ||
while iterator.has_next() do | ||
let name = iterator.next()? | ||
env.out.print(name) | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
try | ||
let iterator = ["Bob"; "Fred"; "Sarah"].values() | ||
while iterator.has_next() do | ||
let name = iterator.next()? | ||
env.out.print(name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
for name in ["Bob"; "Fred"; "Sarah"].values() do | ||
env.out.print(name) | ||
end | ||
actor Main | ||
new create(env: Env) => | ||
for name in ["Bob"; "Fred"; "Sarah"].values() do | ||
env.out.print(name) | ||
end |
39 changes: 30 additions & 9 deletions
39
code-samples/control-structures-loops-while-break-else.pony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
var name = | ||
while moreNames() do | ||
var name' = getName() | ||
if name' == "Jack" or name' == "Jill" then | ||
break name' | ||
end | ||
name' | ||
else | ||
actor Main | ||
let names: Array[String] = [ | ||
"Jack" | ||
"Herbert" | ||
end | ||
"Jill" | ||
] | ||
var current_name: String = "" | ||
|
||
new create(env: Env) => | ||
var name = | ||
while moreNames() do | ||
var name' = getName() | ||
if (name' == "Jack") or (name' == "Jill") then | ||
break name' | ||
end | ||
name' | ||
else | ||
"Herbert" | ||
end | ||
env.out.print("name = " + name) | ||
|
||
fun ref moreNames(): Bool => | ||
try | ||
current_name = names.shift()? | ||
else | ||
return false | ||
end | ||
true | ||
|
||
fun getName(): String => | ||
current_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
var count: U32 = 1 | ||
actor Main | ||
new create(env: Env) => | ||
var count: U32 = 1 | ||
|
||
while count <= 10 do | ||
env.out.print(count.string()) | ||
count = count + 1 | ||
end | ||
while count <= 10 do | ||
env.out.print(count.string()) | ||
count = count + 1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters