Basic While and If
Because Phyton use ident's, I have shown how these ident are use in a condition.
Be careful with thes Ident's, because Phyton do not give a spcific error-code
when Your code does not work as You had intended.
import time digit = 5 while (digit > 0): <TAB>print("Waiting for while to run out...", digit) <TAB>digit-= 1 <-Decrement <TAB>time.sleep_ms(1500) <TAB>if(digit==2): <TAB><TAB>print("Breaking up..") <TAB><TAB>break <CRLF> <CRLF> <CRLF> print( "While is over..\r\nDigit is ", digit )
import time digit = 5 while (digit > 0): print("Waiting for while to run out...", digit) digit-= 1 time.sleep_ms(1500) if(digit==2): print("Breaking up..") break print( "While is over..\r\nDigit is ", digit )
The result is:
>>> import time >>> >>> digit = 5 >>> >>> while (digit > 0): ... time __name__ digit ... print("Waiting for while to run out...", digit) ... time __name__ digit ... digit-= 1 ... time __name__ digit ... time.sleep_ms(1500) ... time __name__ digit ... if(digit==2): ... time __name__ digit ... time __name__ digit ... print("Breaking up..") ... time __name__ digit ... time __name__ digit ... break ... ... ... Waiting for while to run out... 5 Waiting for while to run out... 4 Waiting for while to run out... 3 Breaking up.. >>> print( "While is over..\r\nDigit is ", digit ,"\r\n") While is over.. Digit is 2 >>>
Here I have used module Command:
First CTRL-E,
Then, right-click and select the Paste option.
Third press CTRL-D to finish.
Now the program is running in module.
If not, Press CTRL-C and evt. CTRL-D again.
The result is:
First press CTRL-E >>> paste mode; Ctrl-C to cancel, Ctrl-D to finish 1=== from machine import Pin 2=== import time 3=== 4=== digit = 5 5=== 6=== while (digit > 0): 7=== print("Waiting for while to run out...", digit) 8=== digit-= 1 9=== time.sleep_ms(1500) 10=== if(digit==2): 11=== print("Breaking up..") 12=== break 13=== 14=== 15=== print( "While is over..\r\nDigit is ", digit ,"\r\n") 16=== Waiting for while to run out... 5 Waiting for while to run out... 4 Waiting for while to run out... 3 Breaking up.. While is over.. Digit is 2 >>>