Basic C++
Posted: Wed May 25, 2005 4:03 pm
Some simple Turing -> Python comparisons
Conditionals:
Conditionals:
Code: Select all
if 42 < 34 then
put "Hello"
elsif 56 > 89 then
put "World"
else
put "Foo bar!"
end if[code]
[code]if 42 < 34:
print "Hello"
elif 56 > 89:
print "World"
else:
print "Foo bar!"[code]
Defining a function:
[code]function square (a : int) : int
result a * a
end square[code]
[code]def square(a):
return a * a[code]
While loop:
[code]var counter := 0
loop
put "Hello"
counter += 1
exit when counter = 5
end loop[code]
[code]counter = 0
while counter < 5:
put "Hello"
counter += 1[code]
Looping over an array/list:
[code]var arr : array 1 .. 5 of int := init (3, 4, 1, 7, 8)
for i : 1 .. upper (arr)
put arr (i)
end for[code]
[code]arr = [3, 4, 1, 7, 8]
for x in arr:
put arr[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:3314, old post ID:27094[/size][/color]