Can a for loop be written to create an infinite loop or is it only while loops that do that?

前端 未结 12 1482
时光取名叫无心
时光取名叫无心 2021-01-17 23:58

Can a for loop be written in Java to create an infinite loop or is it only while loops that cause that problem?

12条回答
  •  情话喂你
    2021-01-18 01:00

    you can declare a subpart of the code to be another part in a for loop, example -

    public class (classname) {
        for(int i = 1; i <= 4; i++) {
            for(int j = 1; i <= 4; j++) {
        system.out.println(i + "*" + j + "=" (i*j));
    }
    

    }

    it is almost in infinite loop; if you change int to long, and add more variables, you can practically make it last 25 x 10^12 minutes long

提交回复
热议问题