The Three Laws of Program Flow
01-Introduction
Preparing lunch in daily life:
- Buy ingredients
- Prepare ingredients
- For each ingredient, process according to these conditions:
3.1 If it's vegetables, stir-fry.
3.2 If it's bones, make soup.
3.3 If it's meat, steam. - All ingredients processed
The flow described here includes sequence, loop, and condition.
Most tasks in daily life can be described using these three flows, and so can programs.
02-Answer to Previous Exercise
- First define an animal struct.
- Define different attributes for each.
- Read input and output function types.
- Based on different types, instantiate an animal variable and output animal information.
03-Sequence
fn MakeMilkTea() {
BoilWater(); // Step 1
AddTea(); // Step 2
AddMilk(); // Step 3
PourIntoCup(); // Step 4
}
04-Conditions
if-else, judgment
Pattern matching
05-Loops
for
while
continue
break
06-Exercise
Design a game to guess integers in the range [0-100].
Related Reading
Programmer Wanfeng focuses on AI programming training. Beginners can start making AI projects after watching his tutorial 《30 Lessons · AI Programming Training Camp》 co-produced with Turing Community.
🎓 AI 编程实战课程
想系统学习 AI 编程?程序员晚枫的 AI 编程实战课 帮你从零上手!
- 👉 课程报名:点击这里报名,前3讲免费试听
- 👉 免费试看:B站免费试看前3讲,先看看适不适合自己
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 程序员晚枫 - Python自动化办公与AI编程!

