我应该如何将此循环转换为for循环?
const
TheRightWord = 'hello';
MaximumTries = 3;
var
NTries : integer;
AWord : string;
begin
NTries := 1;
AWord := ' ';
while (AWord <> TheRightWord) and (NTries <= MaximumTries) do
Run Code Online (Sandbox Code Playgroud)
我以为这就是答案:
for (AWord <> TheRightWord) and (NTries <= MaximumTries) do
Run Code Online (Sandbox Code Playgroud)
我必须放在for原地while吗?或者是for i := 1 to 3 do吗?
for numtries := 1 to maxnumtries do begin
if AWord = TheRightWord then
break;
...
Run Code Online (Sandbox Code Playgroud)
如何在退出循环时确定成功或失败(或者,就此而言,如何迭代"AWord"的不同值)是学生的练习:-)
| 归档时间: |
|
| 查看次数: |
234 次 |
| 最近记录: |