C语言基础:break语句使用范例代码
#include <stdio.h> int main() { int counter; for (counter = 1; counter <= 100; counter++) { if (counter == 50) break; printf("%d ", counter); } printf("\nNext loop\n"); for (counter = 100; counter >= 1; counter--) { if (counter == 50) break; printf("%d ", counter); } return 1; }
gcc编译运行结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 Next loop 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51