当前位置:网站首页>Programming learning records - Lesson 4 [branch and loop statements]
Programming learning records - Lesson 4 [branch and loop statements]
2022-07-27 06:22:00 【Autumn mountain chariot God AE】
Conditional statements :if,Switch
if sentence
if sentence :if( Conditional expression ) sentence ; Among them, the judgment of equality should use ==.
Multiple judgment statements ,if( Conditional expression ) sentence ;if( Conditional expression ) sentence ; It means to judge multiple at the same time , And execute , There is no order . There is no influence on each other
if( Conditional expression ) sentence ;else if( Conditional expression ) sentence ;if Block and else if Blocks are mutually exclusive in nature , in other words , Once the statement 1 Has been implemented , The program will skip else if block ,else if Judgment statements and statements in blocks 2 Must be skipped . And when if When the condition in does not hold , To judge else if The statement in .
if( Conditional expression ) sentence ;else sentence ; When if When not executed , perform else The statement in .else only else The sentence is always the one closest to him if Statements match .
switch sentence
swtich( Integer expression ){case: Integer constant expression sentence ;case: Integer constant expression sentence }
It should be noted that , When case When the conditions are met , The statements under all conditions after this condition will be executed sequentially , Until break until .
Loop statement
while loop
Format while( Judge the condition ) { sentence }
break: Out of the loop ;continue: End the code after executing this cycle , So let's do the next loop .
for loop
Format for( Initial value setting statement ; Judgment conditional statement ; Adjustment statement of loop condition )
break: Out of the loop ;continue: End the code after executing this cycle , So let's do the next loop .
Buffer cleanup
getchar() Read the first character of the buffer
Write into the loop to clean up the buffer
while((ch == getchar) != EOF ){;} ; Only when you return EOF, Only when the read value is empty will the loop jump , In this way, the buffer can be completely emptied .
边栏推荐
- 多线程的相关知识
- Related knowledge of multithreading
- 租用香港服务器时单线与三线有什么区别?
- What is the difference between single line and three line when renting servers in Hong Kong?
- Introduction to Wireshark graphical interface
- Dynamic planning for solving problems (3)
- 遥感影像识别-训练策略
- Understand the pointer in a picture
- Socket programming 1: using fork() to realize the most basic concurrency mode
- Multi threaded CAS, synchronized lock principle, JUC and deadlock
猜你喜欢
随机推荐
切线空间以及TBN矩阵
Dynamic planning for solving problems (3)
遥感影像识别进展2022/5/5
Brief introduction to unity window interface
论文写作(收获)
[dynamic planning - steel bar cutting]
ROS node name duplicate
网络原理的简单认识
Robot navigation
Multi threaded CAS, synchronized lock principle, JUC and deadlock
Wireshark function introduction
Remote sensing image recognition imaging synthesis
如何区分独立服务器与VPS主机?
Summary of the use of C # Jason code in TCP communication
[Arduino] reborn Arduino monk (1)
ROS workspace coverage
Solve binary tree (6)
ROS分布式通信
Basic concepts of software testing
Sexy prime number (acwing daily question)









