SRL Archive - News and General

0 is ignored?


josefin

2011-12-04 19:37:14

program new;
var
i: Integer;
begin
while (true) do
begin
for i := 1 to 71 do
begin
Writeln(i);
if i = 20 Then
begin
i := 0
end;
end;
end;
end.

Hi Guys, Why the WriteIn won't write 0 , but will go to 1 directly, instead?
when I use a tpointarray for 72 elements, should I use for 0 to 71, or 0 to 72 ?

Thanks a lot

Kyle Undefined

2011-12-04 19:43:36

for i := 1 to 71 do
That's why. Try

for i := 0 to 71 do

Also, 0 is the start of any array in Pascal. So 0 to 71 is correct. Or, you could do

for i := 0 to High(myArray) do

Narcle

2011-12-04 20:12:13

You can also do

for i := Low(Arr) to High(Arr) do

josefin

2011-12-04 20:12:51

oh sorry. that was me trying with 1 to 71
but if I do for i 0 to 71
writein i

it will go from 1 to 71 only. try it to see

Narcle

2011-12-04 20:16:43

From: josefin
oh sorry. that was me trying with 1 to 71
but if I do for i 0 to 71
writein i

it will go from 1 to 71 only. try it to see


Eh?

program new;
var
i: integer;

begin
for i := 0 to 71 do
Writeln(i);
end.

josefin

2011-12-04 20:17:13

oh I see what's happening. only the first loop will consider the 0.
when I reset the i with i=0, it won't consider the 0 on the loop
so if I want to reset the for loop, I shouldn't use the myarray[0], but start with [1]
right ?

I mean: that loop I'm using on first post is to find bitmaps

Kyle Undefined

2011-12-04 20:21:45

From: josefin
oh sorry. that was me trying with 1 to 71
but if I do for i 0 to 71
writein i

it will go from 1 to 71 only. try it to see


On the first run, it will print 0. After that, even though you're setting it to zero in the loop, once that loop segment is done, your "i" variable is incremented. That's why it prints one after that.

program new;

var
i: Integer;

begin
ClearDebug();
while (true) do
begin
for i := 0 to 71 do
begin
Writeln(i);
if i = 20 Then
begin
i := 0
end;
end;
Exit;
end;
end.

Output:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
Successfully executed.

josefin

2011-12-04 21:42:34

no way to reset the loop without incrementing ?

Gu3st...

2011-12-04 21:44:33

From: josefin
no way to reset the loop without incrementing ?
Try I := -1;

Kyle Undefined

2011-12-04 21:57:00

If "i" is an integer, won't that error out?

josefin

2011-12-04 22:43:09

From: Zyt3x
Try I := -1;


Sounds like a good idea, which I have should thought of :p
Anyway I'll only test it tomorrow to see if Camo ain't right.
Thanks guys

Gu3st...

2011-12-05 02:02:56

From: Camo Developer
If "i" is an integer, won't that error out?
What do you mean? It's not an unsigned integer if that's what you mean?

Kyle Undefined

2011-12-05 02:56:33

Oh, ok. I need to stop thinking in .Net programming lol.

josefin

2011-12-05 04:57:19

awesome =P

Narcle

2011-12-05 16:35:44

program new;
var
i: Integer;

begin
ClearDebug();
while (true) do
begin
for i := 0 to 71 do
begin
if i = 20 Then//"condition"
begin
i := 0
end;

Writeln(i); //code after

end;
Exit;
end;
end.