当前位置:网站首页>[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
2022-06-28 08:26:00 【Autumn sunset】
1. How variables are declared
Standard statement
var Variable name data type = A variable's value
A short statement
Variable name := A variable's value
2. if conditional
1.if conditional
// conditional :
var flag = true
if flag {
fmt.Println(" The result is true")
} else {
fmt.Println(" The result is false")
}
2. Multi condition judgment
// Multi condition judgment
age := 30
if age == 20 {
fmt.Println(" The age is just 20 year ")
} else if age > 20 {
fmt.Println(" Older than 20 year ")
} else {
fmt.Println(" Less than age 20 year ")
}
3. Scope judgment
num The scope of is limited to if In the sentence
// Scope judgment :
if num := 20; num < 30 {
fmt.Println("num Less than 30")
} else {
fmt.Println("num Greater than 30")
}
3.for Loop statement
1. The basic format
for Variable declarations ; conditional ; Step expression {
Loop body statement
}
for num := 0; num < 100; num++ {
fmt.Printf(" from %d To 100\n", num)
}
2. Dead cycle
for ;;{
Loop body statement
}
for ; ; {
fmt.Println(" I am a dead circle ")
}
end. practice
Statistics in a text Numbers , Letter and The number of Chinese characters
package main
import (
"bufio"
"fmt"
"io"
"os"
"unicode"
)
var (
// Numbers Letter Chinese characters
num, wd, han = 0, 0, 0
)
func main() {
// Open file
file, err := os.Open("D:\\ Exercise text .txt")
if err != nil {
fmt.Printf(" An error occurred while reading the file %v\n", err.Error())
}
// Make sure to turn off io flow
defer file.Close()
// Get character buffer stream
reader := bufio.NewReader(file)
// Convert to string
for {
readString, err := reader.ReadString('\n')
if err == io.EOF {
// Description read complete
transition(readString)
fmt.Println(" File read complete ")
break
}
if err != nil {
fmt.Printf(" Error reading character stream %v\n", err)
}
transition(readString)
}
fmt.Println(" Number of numbers : ", num, " Number of letters : ", wd, " The number of Chinese characters :", han)
}
func transition(readString string) {
for a1, str := range readString {
a1 = a1
fmt.Println(str)
if unicode.IsNumber(str) {
num++
}
if unicode.IsLower(str) {
wd++
}
if unicode.IsUpper(str) {
wd++
}
if unicode.Is(unicode.Han, str) {
han++
}
}
}
边栏推荐
- 安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)
- 三体攻击(三维拆分加二分)
- Oracle RAC -- understanding of VIP
- B_QuRT_User_Guide(27)
- Redis02 -- an operation command of five data types for ending redis (it can be learned, reviewed, interviewed and collected for backup)
- 【Go ~ 0到1 】 第一天 6月24 变量,条件判断 循环语句
- Understanding of CUDA, cudnn and tensorrt
- redis02——一篇终结redis的五种数据类型操作命令(可学习、复习、面试、收藏备用)
- CloudCompare&PCL 点云裁剪(基于封闭曲面或多边形)
- 抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
猜你喜欢
微内核Zephyr获众多厂家支持!
Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
Unity gets the coordinate point in front of the current object at a certain angle and distance
Trigonometric transformation formula
The micro kernel zephyr is supported by many manufacturers!
DB
2022巴黎时装周儿童单元6.19武汉站圆满落幕
Kali installation configuration
块级元素上下左右居中的两个小技巧
Activity implicit jump
随机推荐
Oracle view tablespace usage
A - 深海探险
PMP从报考到拿证基本操作,了解PMP必看篇
解决npm ERR! Unexpected end of JSON input while parsing near问题
Kubernetes notes and the latest k3s installation introduction
2022巴黎时装周儿童单元6.19武汉站圆满落幕
CloudCompare&PCL 点云裁剪(基于封闭曲面或多边形)
【力扣10天SQL入门】Day4 组合查询 & 指定选取
关于在cmd中MySQL不能插中文数据的原因
cuda和cudnn和tensorrt的理解
TCP那点事
B_QuRT_User_Guide(27)
Priority of JS operator
Solve NPM err! Unexpected end of JSON input while parsing near
找合适的PMP机构只需2步搞定,一查二问
11grac turn off archive log
NPM clean cache
Trigonometric transformation formula
[learning notes] shortest path + spanning tree
DB