首页 > 解决方案 > 带分号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 在这里做什么呢?

标签: javawhile-loop

解决方案


如果 while 条件完成所有“工作”,则不需要循环体。


推荐阅读