当前位置:网站首页>[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++
}
}
}
边栏推荐
- In flood fighting and disaster relief, the city donated 100000 yuan of love materials to help Yingde
- PLSQL installation under Windows
- 【学习笔记】拟阵
- Almost Union-Find(带权并查集)
- 关于在cmd中MySQL不能插中文数据的原因
- Resolution of Rac grid failure to start after server restart
- 开户券商怎么选择?网上开户是否安全么?
- [learning notes] shortest path + spanning tree
- PMP从报考到拿证基本操作,了解PMP必看篇
- App automated testing appium Tutorial Part 1 - advanced supplementary content
猜你喜欢

Do you know TCP protocol (2)?

匿名页的反向映射

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

Idea related issues

新唐NUC980使用记录:自制开发板(基于NUC980DK61YC)

Introduction, compilation, installation and deployment of Doris learning notes

The preliminary round of the sixth season of 2022 perfect children's model Foshan competition area came to a successful conclusion

安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)

VMware Workstation related issues

关于如何在placeholder中使用字体图标
随机推荐
TCP那点事
Sword finger offer 30 Stack containing min function
[learning notes] simulation
块级元素上下左右居中的两个小技巧
Do you know TCP protocol (1)?
Redis deployment under Linux & redis startup
设置cmd的编码为utf-8
Oracle RAC -- understanding of VIP
Discussion on the application of GIS 3D system in mining industry
PLSQL installation under Windows
图像翻译:UVCGAN: UNET VISION TRANSFORMER CYCLE-CONSISTENT GAN FOR UNPAIRED IMAGE-TO-IMAGE TRANSLATION
Kubernetes notes and the latest k3s installation introduction
Oracle view all tablespaces in the current library
Leetcode swing series
Solve NPM err! Unexpected end of JSON input while parsing near
[learning notes] differential constraint
AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0
On the solution of insufficient swap partition
Unity 获取当前物体正前方,一定角度、距离的坐标点
Force buckle 1884 Egg drop - two eggs