411 REFERENCE · Wikibooks
Computer Programming/Control
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Control flow __TOC__
if (condition):
statement
else:
other statement
if (condition):
statement
else if (condition):
other statement
else if (condition):
other statement
...
else (condition):
another statement
if (temperature is equal to or greater than 40 degrees celsius):
print "It's extremely hot"
else if (temperature is between 30 and 39 degrees):
print "It's hot"
else if (temperature is between 20 and 29 degrees):
print "It's warm"
else if (temperature is between 10 and 19 degrees):
print "It's cool"
else if (temperature is between 0 and 9 degrees):
print "It's cold"
else:
print "It's freezing"
case X :
when 1 :
Walk_The_Dog;
when 5 :
Launch_Nuke;
when 8 or 10 :
Sell_All_Stock;
when others :
Self_Destruct;
esac;
For procedures:
return
For functions:
return Value
goto Label
Dont_Do_Something;
Label :
procedure Use_Return
Do_Something
if Test : return
Do_Something_Else
return
end
procedure Use_Goto
Do_Something
if Test : goto Exit
Do_Something_Else
Exit :
return
end
procedure Use_If
Do_Something;
if not Test :
Do_Something_Else;
fi;
return
end
loop :
Do_Something;
repeat
while (X < 5) :
let X := Calculate_Something
repeat
loop
X := Calculate_Something
until (X > 5)
loop
X := Calculate_Something
if X > 5 : exit
Do_Something (X)
repeat
for I := 1 to 10 :
Do_Something (I)
repeat
for-each I in X :
X [I] := Get_Next_Element;
repeat