Author Topic: For( Loop Issues  (Read 5424 times)

0 Members and 1 Guest are viewing this topic.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
For( Loop Issues
« on: April 07, 2010, 07:46:27 pm »
Ok, so I'm creating a program and everything is working fine but then I get to two consecutive For( and for some reason it is either executing them incredibly fast with false information or is skipping right over them. It is something inside that code because when I isolated that code into another program to test it it does the same thing. Hopefully someone can help me here.

Here is the code in question:

Code: [Select]
For(E,-B+1,-B+D-1
For(F,A+1,A+C-1
Str1+sub("10",1+pxl-Test(E,F),1→Str1
End
End

For testing I was just using:
A=44
B=-27
C=7
D=-7
_→Str1


Also, I just ran a little test thing and it appears that it is the second For( loop that isn't going. Does the variable "F" have issues with the For( command?

Thanks, everyone.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Will_W

  • LV3 Member (Next: 100)
  • ***
  • Posts: 54
  • Rating: +1/-1
    • View Profile
Re: For( Loop Issues
« Reply #1 on: April 07, 2010, 07:49:00 pm »
For(E,-(-27)+1,-(-27)+(-7)-1
For(E,28,19
That's the problem, the start value is higher than the end.
ex de,hl
ld (hl),e
inc hl
ld (hl),d
ld a,(hl)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: For( Loop Issues
« Reply #2 on: April 07, 2010, 08:03:18 pm »
Oh, wow. I knew it'd be something dumb like that :P Thanks Will_W :)
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: For( Loop Issues
« Reply #3 on: April 07, 2010, 08:05:42 pm »
That happened to me often in the past ^^ sometimes took ages for me to figure out.

Fortunately, TI-BASIC and Axe parser are nice enough to not treat such For loops as endless loops, though, like other languages do, according to Will_W

Offline Will_W

  • LV3 Member (Next: 100)
  • ***
  • Posts: 54
  • Rating: +1/-1
    • View Profile
Re: For( Loop Issues
« Reply #4 on: April 07, 2010, 08:10:28 pm »
in java, its for(variable;condition;what to do to make the variable approach the condition)
usually something along the lines of for(int i=0;i>5;i++)
a > condition will behave like BASIC and Axe, but if you did i=5 and started with i=6 or something, it would behave strangely, either giving a compile time error, or incrementing until i overflows and becomes 5.
« Last Edit: April 07, 2010, 08:12:10 pm by Will_W »
ex de,hl
ld (hl),e
inc hl
ld (hl),d
ld a,(hl)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: For( Loop Issues
« Reply #5 on: April 08, 2010, 10:00:30 pm »
wow Java syntax seems weird x.x

It reminds me a bit Casio calcs, except the i++ part of your code that I don't understand.

I think it was something like For 1 to 10->X but I could be wrong. There was another argument for increment rate.

Another thing with TI-83+ for( loops is to always close the parhentesis when your For loop contains only a If:Then:code:End. If the condition is false or something, the For loop takes considerably longer to process and sometimes the rest of the program will run slower, as if a massive memory leak of OVER 9000 KB of RAM occured.

(Texas Instruments should really spend their efforts into fixing their OSes than into DMCA notices and C&D letters.)
« Last Edit: April 08, 2010, 10:01:27 pm by DJ Omnimaga »

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: For( Loop Issues
« Reply #6 on: April 08, 2010, 10:05:11 pm »
Ztrumpet told me it was just to close them if only an If statement occurs after a For( loop and that If/Then were fine without the closing ones, I believe. I would have to check my emails with him to be sure that's what he said, but ya.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: For( Loop Issues
« Reply #7 on: April 08, 2010, 10:08:12 pm »
in java, its for(variable;condition;what to do to make the variable approach the condition)
usually something along the lines of for(int i=0;i>5;i++)
a > condition will behave like BASIC and Axe, but if you did i=5 and started with i=6 or something, it would behave strangely, either giving a compile time error, or incrementing until i overflows and becomes 5.
I think you mean a < condition, because it acts like a "while" and not "repeat"
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: For( Loop Issues
« Reply #8 on: April 08, 2010, 10:55:04 pm »
Ztrumpet told me it was just to close them if only an If statement occurs after a For( loop and that If/Then were fine without the closing ones, I believe. I would have to check my emails with him to be sure that's what he said, but ya.
It's actually mentionned on TI-BD site:

http://tibasicdev.wikidot.com/for

In the optimizations part.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: For( Loop Issues
« Reply #9 on: April 08, 2010, 11:04:57 pm »
Ya, TIBD says its only when an If command (when the condition is false) stands alone after a For(. Unless I'm reading it wrong.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: For( Loop Issues
« Reply #10 on: April 08, 2010, 11:31:40 pm »
yep this is what it says, and my mistake, no Then instructions

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: For( Loop Issues
« Reply #11 on: April 09, 2010, 12:01:55 am »
Oh ok, no worries. Thanks for pointing it out though, I might not have remembered otherwise :P
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: For( Loop Issues
« Reply #12 on: June 01, 2010, 08:48:46 pm »
Ya, TIBD says its only when an If command (when the condition is false) stands alone after a For(. Unless I'm reading it wrong.

Strange, I just tested it out, and the time is almost equal in all four conditions: with the If statement true or false, and with or without the closing parenthesis on the For(.




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: For( Loop Issues
« Reply #13 on: June 01, 2010, 09:25:58 pm »
Try:

0->A
For(Z,0,100
If A=1:0
End

then compare with

0->A
For(Z,0,100)
If A=1:0
End