11 ms·
Ask HN: Anyone knows how to write this code in Pascal?
I have a piede of python code and I would like to know how this would be written in Pascal (it’s for historical research reasons).
I tried to look it up but I couldn’t figure it out for the life of me.
Here’s the python code:
for i in range(116000):
x = i
y = (x*4)/2.71
print(x, y)
Thanks (and sorry for the weird Ask HN :) )
- tonetheman 5y agoCould not tell from the line if you want to print all of those or just one at the end... I just printed at the end Gah formatting is horrible ... [EDIT] here is a gist: https://gist.github.com/tonetheman/db1c3d3cc8a63a0498ed3b16514672e6 https://gist.github.com/tonetheman/db1c3d3cc8a63a0498ed3b165... program TestMe; var i : Longint; x : Longint = 0; y : Real = 0; begin for i:=0 to 116000 do begin x := i; y := (x*4)/2.71; end; writeln(x,y); end.
- camillomiller 5y agoThanks! Really appreciate it!
- compressedgas 5y agoYou might want to check this with a compiler. program example; var i: integer; x: real; y: real; begin for i := 0 to 116000-1 do begin x := i; y := (x*4)/2.71; println(x, y) end end. The difference to note is that the Pascal FOR loop is end inclusive that is it is a closed interval rather than the half open interval that Python uses for its range.
- camillomiller 5y agoThanks, you guys are awesome
- epc 5y agoIt’s been 35+ years for me but basically: Alternate version using while: program hnscratch; var i: integer; x: real; y: real; i := 0; begin; while i <116000 do; begin; x := i; y := (x*4) / 2.71; writeln(x,y); end; end.
- camillomiller 5y agoThanks!
- test666v666 5y agoProgram test(output); var i,x:integer; y:real; begin for i:=1 to 116000 do begin x:=i; y:=(x*4)/2.71; writeln(x,y); end; end.
- test666v666 5y agoTested at https://www.jdoodle.com/execute-pascal-online/ https://www.jdoodle.com/execute-pascal-online/ Program test(output); var i,x:integer; y:real; begin for i:=1 to 10 do begin x:=i; y:=(x*4)/2.71; writeln(x,y); end; end.