xDeltaXen
(xDeltaXen)
March 31, 2022, 6:03pm
1
local Size = 10
local Resolution = 2
for Count1 = 1, Size - Resolution, Resolution do
if Count1 == Size - Resolution then
warn("Last!")
end
end
The code looks simple but the trouble I am having is with the resolution. It will not always print out “Last” depending on what resolution it is.
For example with a resolution of 1 it will print out last but if I change the resolution to 2 it will not.
How can I fix this so it always prints out last iteration, regardless of the resolution?
MP3Face
(MP3Face)
March 31, 2022, 6:07pm
2
That’s because you’re iterating an odd-number of values with an even-number of steps. Your example shows 1 to 8, step interval 2. That’s 1, 3, 5, 7. You don’t reach 8.
xDeltaXen
(xDeltaXen)
March 31, 2022, 6:08pm
3
“How can I fix this so it always prints out last iteration, regardless of the resolution?”
MP3Face
(MP3Face)
March 31, 2022, 6:11pm
4
By addressing that it’s even-steps in an odd-interval.
Alternatively:
if Count1 + Resolution > Size - Resolution then
warn("Last!")
end
as 7+2 > 8 it must be the last interval.
1 Like