如何在C#中创建嵌套的while循环?
对于嵌套的while循环,我们有两个while循环。
第一个循环检查条件,如果条件为真,则转到内部循环,即嵌套循环。
循环1
while (a<25) {
}循环2(在loop1内部)
while (b<45){
}要创建嵌套的while循环,下面是示例代码。
示例
using System;
namespace Program {
class Demo {
public static void Main(string[] args) {
int a=20;
while (a<25) {
int b=40;
while (b<45) {
Console.Write("({0},{1}) ", a, b);
b++;
}
a++;
Console.WriteLine();
}
}
}
}输出结果
(20,40) (20,41) (20,42) (20,43) (20,44) (21,40) (21,41) (21,42) (21,43) (21,44) (22,40) (22,41) (22,42) (22,43) (22,44) (23,40) (23,41) (23,42) (23,43) (23,44) (24,40) (24,41) (24,42) (24,43) (24,44)
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短