Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / im losing my mind today! FOR statement

Author
Message
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Apr 2013 23:58 Edited at: 25th Apr 2013 00:00
Can someone tell me why this prints out 150 and 26 when it should be printing 175 and 1? Only the first iteration does X and Y both equate to 1, so the statement should only reach the ELSE once! I think I'm losing my mind here!





This is basically the exact same thing:


"You're all wrong. You're all idiots." ~Fluffy Rabbit
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 25th Apr 2013 00:10
it prints exactly what it should print

it incrases thing1 every time that x and y are bigger than 1 so if your loop x goes from 2 to 16 and y from 2 to 11, thing1 will be incrased (16-1)*(11-1) times which is 150.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Apr 2013 00:14
There are a total of 176 iterations overall. As far as I can see (and this is why im losing it right now) there is only a single instance where both X and Y equal 1 at the same time.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 25th Apr 2013 00:16
Thing1 = 10 x 15 = ?? You guessed it, 150.

Thing2 = 11 + 15 = ?? You guessed it, 26.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 25th Apr 2013 00:19
It reads "if x != 1 and y != 1" meaning that the if-clause will only be run when neither x nor y is 1.
That means that the else clause will be run when either of them is


"Why do programmers get Halloween and Christmas mixed up?"
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Apr 2013 00:25 Edited at: 25th Apr 2013 00:26
Still makes no sense. I hate my brain today, I can't process simple logic at all.

So how would I write the IF statement I wanted the results of thing1 and thing2 swapped? (if that makes sense) In other words, I want to ignore when both X and Y are 1 without using an ELSE statement. I seriously want to hit myself with a hammer today




"You're all wrong. You're all idiots." ~Fluffy Rabbit
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Apr 2013 00:31
I wrote out my statement by hand:

1 <> 1 AND 1 <> 1 FALSE FALSE = FALSE
1 <> 1 AND 2 <> 1 FALSE TRUE = FALSE
1 <> 1 AND 3 <> 1 FALSE TRUE = FALSE
1 <> 1 AND 4 <> 1 FALSE TRUE = FALSE
1 <> 1 AND 5 <> 1 FALSE TRUE = FALSE
1 <> 1 AND 6 <> 1 FALSE TRUE = FALSE


Finally, it clicked into my thick caveman skull. I think I should just call it quits for today.

"You're all wrong. You're all idiots." ~Fluffy Rabbit

Login to post a reply

Server time is: 2026-07-07 07:56:27
Your offset time is: 2026-07-07 07:56:27