while condition :

while loop

Use: while condition :
.    statements 
Description: Runs the following block of statements while the condition is true
Parameters: condition An expression that evaluates to a true or  false value (1 or 0). If the condition is true (1) then the block of code that follows is run. If the condition is false (0) then the following block of code is skipped.
Returns: None
Related: for, if, if else, condition, break, continue


If the condition evaluates to true (or a non zero value) then the following statements are executed. The statements will continue to be run as long as the condition is true. (The statements are a block of code is where all the lines are indented by the same number of space characters)

The condition can be a value or an expression. An expression may contain, variables, comparison operators, such as == , < , >= etc.

The break statement can be used to break out of the loop, and the continue statement can be used to skip the rest of the current loop.

 

Example:

pindir(P1_0, OUT)       # Set port P1_0 as an output (this is the Launchpad red led)
while 1:                # do forever
   out(P1_0, 0)         # set the output pin P1_0 (red led) to a 0 (off)
   wait(500)            # wait for 500ms  (half a second)
   out(P1_0, 1)         # set the output pin P1_0 (red led) to a 1 (on)
   wait(500)

When the output value is 0 the voltage at the output pin will be 0v. When it the output value is a 1 the output voltage will be equal to the supply voltage of the microcontroller.