# plz help me2

can any1 plz explain this source 4 me? It's about loops and i don't get it. (i'm a beginner)
program CELSIUS_TABLE ( output );
var celsius : integer; fahrenheit : real;
begin
writeln('Degree''s Celsius Degree''s Fahrenheit');
for celsius := 1 to 20 do
begin
fahrenheit := ( 9 / 5 ) * celsius + 32;
writeln( celsius:8, ' ',fahrenheit:16:2 )
end
end.

• : can any1 plz explain this source 4 me? It's about loops and i don't get it. (i'm a beginner)
: program CELSIUS_TABLE ( output );
: var celsius : integer; fahrenheit : real;
: begin
: writeln('Degree''s Celsius Degree''s Fahrenheit');
: for celsius := 1 to 20 do
: begin
: fahrenheit := ( 9 / 5 ) * celsius + 32;
: writeln( celsius:8, ' ',fahrenheit:16:2 )
: end
: end.

What do you mean explain? If you want to know what it does, it writes 1 through 20 celsius and the equivalent farenheight temperature. If you want to know how it works here is another example that is easier to explain:

[code]
for I := 97 to 122 do
begin
WriteLn('Ascii Character #', I, ' = ' + Chr(I));
end;
[/code]

What FOR does is runs the code between the begin..end; block over for as many times as you specify. In this case it runs it with an inital value of 97 and a final value of 122. So in total the block of code is ran 26 times.

• I want to know how it works.

• : can any1 plz explain this source 4 me? It's about loops and i don't get it. (i'm a beginner)
: program CELSIUS_TABLE ( output );
: var celsius : integer; fahrenheit : real;
: begin
: writeln('Degree''s Celsius Degree''s Fahrenheit');
: for celsius := 1 to 20 do
: begin
: fahrenheit := ( 9 / 5 ) * celsius + 32;
: writeln( celsius:8, ' ',fahrenheit:16:2 )
: end
: end.
:

Hello, I'll try to explain...

First, the "celsius" and "fahrenheit" - variables are defined.
Next, the line "Degree's Celsius Degree's Fahrenheit" are written.
And then comes a FOR-loop, where all the action are done...

In the line "for celsius := 1 to 20 do" it's defined that this loop will be run 20 times. The first time the variable "celsius" are set to 1. The next time it's set to 2. The third time to 3, and all the way up to 20.

Within the "begin / end" - block, the value of "celsius" (1 for the first time the loop runs), are used, so that the next line look's like this:
fahrenheit := ( 9 / 5 ) * 1 + 32; (This is the formula for converting degrees celcius to degrees fahrenheit!!)

Then, the Writeln-line writes the two values.
(1 degree celcius are 33,8 degrees fahrenheit.)
The second time the loop run's, the celsius-variable are set to 2, and the line will loke like this:
fahrenheit := ( 9 / 5 ) * 2 + 32;
Then again, the to values are written.
(2 degree celcius are 35,6 degrees fahrenheit.)
The third time the loop run's, the celsius-variable are set to 3, and the line will loke like this:
fahrenheit := ( 9 / 5 ) * 3 + 32;
Then again, the to values are written.
(3 degree celcius are 37,4 degrees fahrenheit.)

And so it goes all the way up to 20....
fahrenheit := ( 9 / 5 ) * 20 + 32;
(20 degree celcius are 68 degrees fahrenheit.)

So you will have 20 lines of temperatures on your screen when the program has come to an end.
I hope you understood this...

• thanks, i really did understand that, it really helped me. I have another one that i don't understand.
program FOR_TEST ( output );
var s, j, k, i, l : integer;
begin
s := 0;
for j:= 1 to 5 do
begin
write( j );
s := s + j
end;
writeln( s );
for k := 0 to 1 do write( k );
for i := 10 downto 1 do writeln( i );
j := 3; k := 8; l := 2;
for i := j to k do writeln( i + l )
end.