第16节--break&continue&pass

break:直接跳出整个循环
continue:跳出本次循环,接着进行下次循环

code

number = 59

while True:
    guess = int(input("enter an integer: "))
    if guess == number:
        break
    elif guess <number:
        print("the number is higher than that ")
        continue
    else:
        print("the number is lower than that ")
        continue

print("bingo you are right") 
print("done")

pass:执行完下面的内容,再返回开始处,进行下一轮的循环

code(注意continue和pass的区别)

a_list = [0,1,2]

print("using continue")
for i in a_list:
    if not i:
        continue
    print(i)

print("using pass")
for i in a_list:
    if not i:
        pass
    print(i)

console

using continue
1
2
using pass
0
1
2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,你的第一个问题是关于一个嵌入式系统的功能实现,我可以回答。这个系统主要有三个功能:一个是跑马灯的循环显示,一个是按下 KEY1 触发 LED 的切换,另一个是按下 KEY3 触发 LED 的闪烁。其中 KEY3 中断可以抢占 KEY1 中断。具体的实现可以参考以下代码: ```c #include <reg52.h> unsigned char code LED[8] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F}; // 逐个点亮的数码管数据 void main() { TMOD = 0x10; // 定时器2工作在模式1 TH1 = 0xFC; // 定时器2初值 TL1 = 0x66; ET1 = 1; // 允许定时器2中断 TR1 = 1; // 启动定时器2 EX0 = 1; // 允许外部中断0 IT0 = 1; // 设置为下降沿触发 EX1 = 1; // 允许外部中断1 IT1 = 1; // 设置为下降沿触发 EA = 1; // 允许中断 while (1) { // 循环执行跑马灯的操作 } } void Timer1() interrupt 3 { // 定时器2中断服务函数 static unsigned char i = 0; switch (i) { case 0: P1 = LED[0]; P2 = LED[7]; break; case 1: P1 = LED[1]; P2 = LED[6]; break; case 2: P1 = LED[2]; P2 = LED[5]; break; case 3: P1 = LED[1]; P2 = LED[6]; break; case 4: P1 = LED[0]; P2 = LED[7]; break; } i = (i + 1) % 5; TH1 = 0xFC; // 重新设置定时器2初值 TL1 = 0x66; } void External0() interrupt 0 { // 外部中断0服务函数 static unsigned char i = 0; while (i < 3) { // 切换间隔时间为200ms,循环3次 P1 = 0x55; P2 = 0xAA; i++; delay(200); // 延时200ms,需要自己实现 } i = 0; } void External1() interrupt 2 { // 外部中断1服务函数 static unsigned char i = 0; while (i < 5) { // 闪烁间隔时间为400ms,闪烁5次 P1 = P2 = 0xFF; i++; delay(400); // 延时400ms,需要自己实现 } i = 0; } void delay(unsigned int t) { // 延时函数 unsigned int i, j; for (i = 0; i < t; i++) { for (j = 0; j < 1000; j++) { // 空循环 } } } ``` 以上是一个简单的实现,具体的操作流程和函数实现需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值