1.while循環結構的使用;
2.隨機數的獲取;
3.do... while 循環體的使用;
4.for循環結構的使用;
5.break 與 continue 的區別;
1.while循環結構的使用
// while 結構
// while (條件表達式) {
// 循環體;
// }
//執行順序:判斷條件表達式是否成立,如果成立,執行循環體,執行完循環體后,再判斷條件表達式是否成立,如此往復,直到條件表達式不成立,跳出while循環;
//死循環:
// int a = 5;
// while (a > 0) {
// // }
//打印5次 hello world:
// int a = 5;
// while (a > 0) {
// printf("Hello World!/n");
// a--;
// }
// printf("END/n");
// int a =0;
// while (a < 5) {
// printf("%dHello World!/n", a);
// a++;
// }
// int a = 0;
// while (a <= 100) {
// printf("%d ",a);
// a++;
// }
// int a = 100;
// while (a >= 0) {
// printf("%d ", a);
// a--;
// }
//計算1~100的和:
// int i = 1, sum = 0;
// while (i <= 100) {
//// sum += i;
//// i++;
// sum += i++;
// }
// printf("sum = %d/n", sum);
//輸出1~100的偶數:
//方法一:
// int i = 0;
// while (i <= 100) {
// if (i % 2) {
// printf("%d ",i);
// }
// i++;
// }
//方法二:
// int i = 0;
// while (i <= 100) {
// printf("%d ", i);
// i += 2;''
// }
//打印1~100間7的倍數:
// int i = 1;
// while (i <= 100) {
// if (i % 7 == 0) {
// printf("%d ", i);
// }
// i++;
// }
//打印1~100間個位為7:
// int i = 1;
// while (i <= 100) {
// if (i % 10 == 7) {
// printf("%d ", i);
// }
// i++;
// }
//打印1~100間十位為7:
// int i = 1;
// while (i <= 100) {
// if (i / 10 == 7) {
// printf("%d ", i);
// }
// i++;
// }
//打印1~100間不是7的倍數且不包含7的數:
// int i = 1;
// while (1 <= 100) {
// if (i % 7 != 0 && i % 10 != 7 && i /10 != 7) {
// printf("%d ", i);
// }
// i++;
//
//
// }
// int a = 0,b = 0;
// for (a = 1; a <= 100; a++) {
// printf("%d ",a);
// for (b = 1; b <= 10; b++) {
// printf("/n");
// }
// }