Skip to content

Commit f33ce0e

Browse files
committed
Upgrade For.Loop() function
1 parent 7b596d3 commit f33ce0e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Core/For.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ namespace SteveSharp.Core;
22

33
public static class For
44
{
5-
public static string Loop(int from, int to, string create, string replaces = ""){
6-
string commands = "";
7-
for(int i = from; i <= to; i++){
8-
commands += create.Replace(replaces, i.ToString()) + '\n';
5+
public static string Loop(int to, Func<int, List<String>> block, int from = 0) {
6+
List<List<string>> fullBlock = new();
7+
for(int i = from; i <= to; i++) {
8+
fullBlock.Add(block(i));
99
}
10-
return commands;
10+
List<string> ret = new();
11+
foreach(var codeBlock in fullBlock) {
12+
foreach(var command in codeBlock) {
13+
ret.Add(command);
14+
}
15+
}
16+
return string.Join("\n", ret);
1117
}
1218
}

0 commit comments

Comments
 (0)