Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python - Common Conditional Statements

#if, elseif, else
if (myNumber == 5):
    print "My Number is Five";
elif (myNumber == 3.14):
    print "My Number is Pi";
else:
    print "My Number is neither Five nor Pi 
";

 

#while loop
while (myNumber != 0):
    print "My Number is: ", myNumber;
    myNumber -= 1;
print "
";

#for loop
for myNumber in range (0, 5):
    print "My Number is: ", myNumber;
print "
";

#foreach loop
for currentElement in myList:
    print "The current element is: ", currentElement;
Source by knowledge.ni.com #
 
PREVIOUS NEXT
Tagged: #Python #Common #Conditional #Statements
ADD COMMENT
Topic
Name
6+2 =