java - 带分号java的while循环
问题描述
为什么我们使用 while 循环和分号 ( ;
) 紧随其后?
我以这段代码为例:
public static void Register()
{String name,code;
int posStudent,posCourse;
System.out.println("-----------------------------------------------");
System.out.println("Enter the name of the student");
name=in.next();
while ((posStudent=VerifyTheStudentName(name))==-1);
System.out.println("-----------------------------------------------");
System.out.println("The list of available courses is:");
for(int i=0;i<courses.size();i++)
System.out.println(courses.get(i));
System.out.println("-----------------------------------------------");
System.out.println("Enter the course code");
code=in.next();
while((posCourse=VerifyTheCourseCode(code))==-1);
students.get(posStudent).registerTo(courses.get(posCourse));
}
那么 while 在这里做什么呢?
解决方案
如果 while 条件完成所有“工作”,则不需要循环体。
推荐阅读
- ios - 签约“Runner”需要开发团队。在签名和功能编辑器中选择一个开发团队
- nuget - 从 .NET 4.6.2 应用程序安装多目标 Nuget 的 .NET Standard 版本?
- javascript - Javascript Web 中的共享元素转换
- python-3.x - 我在使用 if 语句和可能的 def 函数时遇到问题
- javascript - 我已经下载了syncfusion,我不知道如何运行syncfusion 演示代码。请任何人都知道。发生此错误
- c++ - 迭代具有 n 和 n*n 元素的向量
- ruby - Ruby net/http/get 不适用于 url,但适用于 uri。为什么?
- mysql - 查找某人访问酒店最多的时间
- javascript - Firebase 无法创建新文档
- google-classroom - course.getCourseMaterialSets() 为 Google 课堂课程资料返回空