pacage imo
func imo() {
println("hello.world")
}
package imo
func imo(){
println ("hhello, correct answer")
println ("hello" + "correct answer")
}
package imo
func imo(){
/*
*/
println ("hello, world")
// println ("hello, world")
}
panag imo
func imo(){
println(2)
printlm(2 + 3)
println(4 - 7)
}
One of the types of variables (boxes for storing data in programming) It's like a rule that "you can put a character string (a collection of characters) in that box"
pacage imo
func imo(){
var n int
n = 100
println(n)
}
pacage imo
func imo (){
var n int =100
println(n)
}
In Go, when variable definition and value assignment are performed at the same time, such as "var a int = 100" Data type specification omitted ok ** "var a = 100" ** and int omitted ok
package imo
func main(){
var a = 100
println(a)
}
Furthermore, if you write like " b: = 200", it has the same meaning as "var b int = 200" </ font> = (equal) instead of: = (colon and equal) This way of writing is ok
package imo
func imo(){
b:= 200
println(b)
}
package main
func main() {
a := 100
b := 200
prntcl(100,200)
}
It seems that it is OK to omit it at the highest
Self-assignment </ font>
package imo
func imo(){
n := 10
n=n + 20
println(n)
}
If a conditional expression is specified after if and the condition is satisfied, the inside of {} is executed.
package main
func main(){
score := 100
if score > 80{
printnl ("well done")
}
}
Comparison operator | |
---|---|
x <= y | Holds when x is less than or equal to y |
x >= y | Holds when x is greater than or equal to y |
There are two values for "validity type", "true" and "false". A conditional expression using a comparison operator has a value of "true" when it holds, and "false" when it does not hold.
package main
func main(){
println(3 > 2)
println(3 > 5)
}
> _ Console
ture
false
operator | |
---|---|
== | Ture when the left and right sides are equal |
!= | When not equal ture |
< | True when the right side is larger |
<= | When the right side is larger or equal ture |
> | When the right side is small ture |
>= | When the right side is small or equal ture |
package main
func main(){
score := 50
if score > 80 {
println ("well done")
} else {
println ("Let's do our best")
}
}
eles if
package main
func main() {
score := 70
if score == 100{
println ("well done")
} eles if score >= 60{
println ("fair")
} eles{
println ("OK")
}
}
:dancer: eles if (2)
package main
func main() {
score := 100
if score == 100{
println ("well done")
} eles if score >= 60{
println ("fair")
} else {
println ("Let's do our best")
}
}
The conditional expression "whether condition 1 and condition 2 are satisfied" is written as "condition 1 && condition 2" using "&&". && corresponds to "Katsu" in Japanese. Combining multiple conditional expressions using && will result in true as a whole only if all conditional expressions are true
package main
func main() {
time := 14
if time > 10 && time < 18 {
println ("working hours")
}
}
The conditional expression "whether condition 1 or condition 2 holds" is "||"Condition 1"||Write as "Condition 2".||Is equivalent to "or" in Japanese. ||When multiple conditional expressions are combined using, if even one of the multiple conditional expressions is true, the whole becomes true.
package main
func main() {
time := 15
if time == 10 || time == 15 {
println ("goal")
}
}
package main
func main(){
time := 9
if !(time == 18) {
println ("not leaving time")
}
}
case 0:
println ("bad")
case 1, 2:
println ("Kichi")
case 3, 4:
println ("Nakayoshi")
case 5:
println ("Daikichi")