当前位置:网站首页>MOOC Weng Kai C language fourth week: further judgment and circulation: 3. Multiple branches 4. Examples of circulation 5. Common errors in judgment and circulation
MOOC Weng Kai C language fourth week: further judgment and circulation: 3. Multiple branches 4. Examples of circulation 5. Common errors in judgment and circulation
2022-07-28 07:03:00 【W.934】
One 、 Multiple branches
switch-case
switch( Control variable expression ){
case Constant :
sentence
......
case Constant :
sentence
......
default:
sentence
......
}
Control expressions can only be integer results .( The expression can only be int Type of )
Constants can be constants , It can also be an expression for constant calculation .(C99 You can use )
break
case Can't stop the sentence from going on , and break Sure .
switch Statement can be seen as a calculation based jump , After calculating the value of the control expression , The program will jump to the matching case( Branch label ) It's about . The branch label just indicates switch Road signs at internal locations , After executing the last statement in the branch , If not at the back break, It will be executed in sequence to the following case In go to , Until I met a break, perhaps switch End .
Two 、 An example of a cycle
1. Cycle calculation
A little routine : Save the original value before calculating , It may be useful later .
2. Count cycle
A little routine : If you want to simulate running a large number of cycles , It can simulate fewer cycles , And then infer .
3. Calculate the average

4. Guess the game
random number :rand
Every call rand() You get a random integer .
%100:x%n The result is [0,n-1] It's an integer of
5. Decomposition of integers
An integer is composed of 1 To multiple digits , How to decompose the numbers in each bit of an integer , Then calculate .
Do... To an integer %10 The operation of , You get its single digits ;
Do... To an integer /10 The operation of , Just remove its single digits ;
And then to ② What are the results %10, You get the original ten digits ;
And so on ......
3、 ... and 、 Common mistakes in judgment and circulation
1.if Common mistakes in sentences
1) Forget the braces // Forever if and else Followed by {}, Even if there was only one sentence behind .
2)if Semicolon after //if No semicolon after the statement ;
3) Misuse == and = //if Only required () The value in is zero or non-zero ( Yes or no )//= It's assignment // Be careful warning Tips
4)else Use
Code style. :
stay if and else Then you must add braces to form a statement block ; The statements in braces are indented by a tab The location of .
边栏推荐
- DHCP原理与配置
- SSH service configuration
- Technology sharing | send requests using postman
- Scratch command
- Ubuntu18.04 set up redis cluster [learning notes]
- Esxi community network card driver updated again
- Blue bridge code error ticket
- Ubuntu18.04搭建redis集群【学习笔记】
- Principle and configuration of NAT and pat
- How to describe a bug and the definition and life cycle of bug level
猜你喜欢
随机推荐
Small tips
DOM Foundation
Software testing (concept)
QGraphicsView提升为QChartView
Principle and configuration of NAT and pat
MySQL master-slave
MOOC翁恺C语言 第四周:进一步的判断与循环:1.逻辑类型与运算2.级联和嵌套的判断
Results fill in the blanks for beer and drinks
bond模式配置
Iptables firewall
Custom components -- slots
My deployment notes
DHCP service
Results fill in the blank. How many days of national day are Sundays (solved by pure Excel)
RAID磁盘阵列
Firewall - iptables firewall (four tables and five links, firewall configuration method, detailed explanation of matching rules)
Applet custom components - data, methods, and properties
What is the most practical gift for Tanabata? A gift that will never go wrong is worth buying
JSON notes
小甲鱼C(第六章数组1、2)









