如何管理 while 循环伪代码中的循环次数

How to manage the number of loops in while loop Pseudocode

我是初学者,想问一下 While Loop Pseudocode 的循环次数,如果我想让它由用户输入而不指定多少,我应该这样写吗?还是必须先申报SM?

谢谢

   BEGIN
          Student = 0
          WHILE Student < SM
                      Get Work Efficiency, Task Completion Effectiveness, Team Work, SM # SM is 
                      the number of students’ marks to be entered
                      Sum = Work Efficiency + Task Completion Effectiveness + Team Work
                      Competency = (Sum / 50) * 100
                      If Competency >= 70%
                                       grade = ‘A’
                                       display = “Exceed Expectation!”
                      else if Competency >= 40%  AND  Competency < 70%  
                                       grade = ‘B’
                                       display = “Meet Expectation”
                      else if Competency >= 0%  AND  Competency < 40%  
                                       grade = ‘C’
                                       display = “Below Expectation”
                      else 
                                       display = “Invalid input”
                      End if
                      Student = Student + 1
          END WHILE
   END

正如您所说,SM 是由用户输入提供的,因此您应该在某处提及它。有很多种编写伪代码的方法,它们主要取决于您的需要,因此您可以例如写:

SM <- integer user input
[rest of your code]

或者将它包装在一个函数中(这样你就可以表明返回值依赖于 SM 的值:

function foo(SM):
    [rest of your code]