Recent

Author Topic: for..next  (Read 1074 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 392
for..next
« on: August 24, 2025, 08:35:03 pm »
Code: Pascal  [Select][+][-]
  1.  i:= 0;
  2.  number := 0;
  3.  for i := number to (number+1) do
  4.  begin
  5.          
  6.  end;
  7.  

it executes twice but i is in both cases 0 ?
lazarus 3.2-fpc-3.2.2-win32/win64

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12768
  • FPC developer.
Re: for..next
« Reply #1 on: August 24, 2025, 08:41:24 pm »
If the compiler determines that the value of I is not used, it can optimise it. If you then look with the debugger, the value doesn't make sense, but that is not really a problem.

What did you exactly do to test ?

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 392
Re: for..next
« Reply #2 on: August 24, 2025, 08:43:05 pm »

What did you exactly do to test ?

Put breakpoint, check i value that I'm using inside loop.

EDIT: ahh, my bad. Thanks for opening my  eyes (-: number and i switched places in my brain.
« Last Edit: August 24, 2025, 08:46:00 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

 

TinyPortal © 2005-2018