Verify control-flow invariants and document the development contract
This commit is contained in:
1 parent
71d29261a8
commit
1dc088b602
22 files changed
+269
-80
No files matched your search
@@ -0,0 +1,35 @@
|
||||
# @knowledge 筛选读数
|
||||
|
||||
跳过无效读数,遇到停止标记时结束扫描,返回已接收读数的总和。
|
||||
|
||||
## @exec main
|
||||
|
||||
`读数 = [2, -1, 3, 0, 9]`
|
||||
|
||||
`位置 = 0`
|
||||
|
||||
`合计 = 0`
|
||||
|
||||
- `while 位置 < 长度(读数)`:逐项读取。
|
||||
|
||||
`当前 = 读数[位置]`
|
||||
|
||||
`位置 = 位置 + 1`
|
||||
|
||||
1. `if 当前 < 0`:跳过无效读数。
|
||||
|
||||
`continue`
|
||||
|
||||
2. `else if 当前 == 0`:遇到停止标记。
|
||||
|
||||
`break`
|
||||
|
||||
3. `else`:累计有效读数。
|
||||
|
||||
`合计 = 合计 + 当前`
|
||||
|
||||
`end`
|
||||
|
||||
`end`
|
||||
|
||||
`return 合计`
|
||||
Reference in new issue
Block a user