当前位置:网站首页>[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++
}
}
}
边栏推荐
- Do you know TCP protocol (2)?
- AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0
- B_ QuRT_ User_ Guide(27)
- ROS 笔记(08)— 服务数据的定义与使用
- Eslint 语法监测关闭
- Selenium reptile
- B_QuRT_User_Guide(26)
- Solve NPM err! Unexpected end of JSON input while parsing near
- js运算符的优先级
- Trailing Zeroes (II)
猜你喜欢

AWS saves data on the cloud (3)

微内核Zephyr获众多厂家支持!

Infinite penetration test

Unity gets the coordinate point in front of the current object at a certain angle and distance

Redis02 -- an operation command of five data types for ending redis (it can be learned, reviewed, interviewed and collected for backup)

城联优品向英德捐赠抗洪救灾爱心物资

AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0

2022第六季完美童模 佛山赛区 初赛圆满落幕

Do you know TCP protocol (1)?

Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
随机推荐
B_QuRT_User_Guide(28)
设置cmd的编码为utf-8
Preparation for Oracle 11g RAC deployment on centos7
【力扣10天SQL入门】Day4 组合查询 & 指定选取
Discussion on the application of GIS 3D system in mining industry
WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持
Force buckle 1024 video splicing
Not so Mobile
Two tips for block level elements
[learning notes] linear basis
Super Jumping! Jumping! Jumping!
Priority of JS operator
Installing MySQL under Linux
Redis deployment under Linux & redis startup
整数划分
11grac turn off archive log
Reverse mapping of anonymous pages
Chenglian premium products donated love materials for flood fighting and disaster relief to Yingde
Unity - use of API related to Pico development input system ---c
关于在cmd中MySQL不能插中文数据的原因