for 和 while 和 do...while

while循环和for循环“异曲同工”:

image

 

do...while:

image

image

 

image

 

死循环:

 

image

 

标号:

image

死循环应用案例:

 1 import java.util.Scanner;
 2 public class c
 3 {
 4     public static void main(String[] args)
 5     {
 6         //loop 循环的意思,lop:标号名
 7         lop:while(true)
 8         {
 9             System.out.println("---------------------");
10             System.out.println("请输入1-7的数字:");
11             Scanner sc = new Scanner(System.in);
12             int week = sc.nextInt();
13             
14             switch(week)
15             {
16                 case 0 :
17                     System.out.println("欢迎下次光临:)");
18                     break lop;
19                 case 1 :
20                     System.out.println("周一");
21                     break;
22                 case 2 :
23                     System.out.println("周二");
24                     break;
25                 case 3 :
26                     System.out.println("周三");
27                     break;
28                 case 4 :
29                     System.out.println("周四");
30                     break;
31                 case 5 :
32                     System.out.println("周五");
33                     break;
34                 case 6 :
35                     System.out.println("周六");
36                     break;
37                 case 7 :
38                     System.out.println("周七");
39                     break;
40                 default:
41                     System.out.println("输入错误数字!!!");
42                     break;
43             }
44         }
45     }
46 }

 

posted @ 2025-09-26 14:11  字节虫  阅读(10)  评论(0)    收藏  举报