mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 15:51:41 +03:00
Uniform output format
This commit is contained in:
parent
4fcac31e9c
commit
749e81ace2
@ -369,19 +369,17 @@ for animal = ["dog", "cat", "mouse"]
|
|||||||
println("$animal is a mammal")
|
println("$animal is a mammal")
|
||||||
# You can use $ to interpolate variables or expression into strings
|
# You can use $ to interpolate variables or expression into strings
|
||||||
end
|
end
|
||||||
# prints:
|
# => dog is a mammal
|
||||||
# dog is a mammal
|
# => cat is a mammal
|
||||||
# cat is a mammal
|
# => mouse is a mammal
|
||||||
# mouse is a mammal
|
|
||||||
|
|
||||||
# You can use 'in' instead of '='.
|
# You can use 'in' instead of '='.
|
||||||
for animal in ["dog", "cat", "mouse"]
|
for animal in ["dog", "cat", "mouse"]
|
||||||
println("$animal is a mammal")
|
println("$animal is a mammal")
|
||||||
end
|
end
|
||||||
# prints:
|
# => dog is a mammal
|
||||||
# dog is a mammal
|
# => cat is a mammal
|
||||||
# cat is a mammal
|
# => mouse is a mammal
|
||||||
# mouse is a mammal
|
|
||||||
|
|
||||||
for pair in Dict("dog" => "mammal", "cat" => "mammal", "mouse" => "mammal")
|
for pair in Dict("dog" => "mammal", "cat" => "mammal", "mouse" => "mammal")
|
||||||
from, to = pair
|
from, to = pair
|
||||||
@ -405,11 +403,10 @@ let x = 0
|
|||||||
x += 1 # Shorthand for x = x + 1
|
x += 1 # Shorthand for x = x + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# prints:
|
# => 0
|
||||||
# 0
|
# => 1
|
||||||
# 1
|
# => 2
|
||||||
# 2
|
# => 3
|
||||||
# 3
|
|
||||||
|
|
||||||
# Handle exceptions with a try/catch block
|
# Handle exceptions with a try/catch block
|
||||||
try
|
try
|
||||||
@ -502,10 +499,9 @@ end
|
|||||||
# => all_the_args (generic function with 2 methods)
|
# => all_the_args (generic function with 2 methods)
|
||||||
|
|
||||||
all_the_args(1, 3, keyword_arg=4)
|
all_the_args(1, 3, keyword_arg=4)
|
||||||
# prints:
|
# => normal arg: 1
|
||||||
# normal arg: 1
|
# => optional arg: 3
|
||||||
# optional arg: 3
|
# => keyword arg: 4
|
||||||
# keyword arg: 4
|
|
||||||
|
|
||||||
# Julia has first class functions
|
# Julia has first class functions
|
||||||
function create_adder(x)
|
function create_adder(x)
|
||||||
|
Loading…
Reference in New Issue
Block a user