Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit f06f31f

Browse files
committed
新增简单循环测试功能,包含简单循环、嵌套循环和While循环的性能测试,旨在验证循环内存管理的有效性。
1 parent b8b3fbe commit f06f31f

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

simple_loop_test.cn

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// CodeNothing v0.7.6 简单循环测试
2+
// 测试循环专用内存管理功能
3+
using lib <io>;
4+
5+
fn test_simple_loop(): int {
6+
println("🔄 测试简单循环");
7+
8+
sum : int = 0;
9+
i : int = 1;
10+
while (i <= 1000) {
11+
sum = sum + i;
12+
i = i + 1;
13+
};
14+
15+
println("简单循环结果: " + sum);
16+
return sum;
17+
};
18+
19+
fn test_nested_loop(): int {
20+
println("🔄 测试嵌套循环");
21+
22+
result : int = 0;
23+
24+
i : int = 1;
25+
while (i <= 50) {
26+
j : int = 1;
27+
while (j <= 50) {
28+
temp : int = i * j;
29+
result = result + temp;
30+
j = j + 1;
31+
};
32+
i = i + 1;
33+
};
34+
35+
println("嵌套循环结果: " + result);
36+
return result;
37+
};
38+
39+
fn test_while_loop(): int {
40+
println("🔄 测试While循环");
41+
42+
counter : int = 0;
43+
sum : int = 0;
44+
45+
while (counter < 500) {
46+
sum = sum + counter;
47+
counter = counter + 1;
48+
};
49+
50+
println("While循环结果: " + sum);
51+
return sum;
52+
};
53+
54+
fn main(): int {
55+
println("=== CodeNothing v0.7.6 循环内存管理测试 ===");
56+
println("");
57+
58+
result1 : int = test_simple_loop();
59+
result2 : int = test_nested_loop();
60+
result3 : int = test_while_loop();
61+
62+
total : int = result1 + result2 + result3;
63+
64+
println("");
65+
println("=== 测试完成 ===");
66+
println("总计结果: " + total);
67+
68+
return total;
69+
};

0 commit comments

Comments
 (0)