 Author Topic: While not statement?  (Read 1675 times) baicskillet

• Mc. Print
• • Posts: 29 While not statement?
« on: 2010-Feb-28 »
Hi, is there some sort of statement to use in a while or for that checks if a condition is NOT true? Like, the !(variable) statement of pascal and such? Or the WHILE NOT (condition1)?

thankyou! Moru

• Prof. Inline
•       • • Posts: 1791 Re: While not statement?
« Reply #1 on: 2010-Feb-28 »
In basic you write like this:

IF x <> 5 baicskillet

• Mc. Print
• • Posts: 29 Re: While not statement?
« Reply #2 on: 2010-Mar-01 »
OK, thank you for your reply, but what about when there's many conditions that are NOT supposed to be true? If I may, this is the code I'm talking about:

Code: (glbasic) [Select]
repeat
x := random(16)
until (x in [1..6,9..15])and(x<>Col1)and(x<>Col2)and(x<>Col3)and(x<>Col4);
Col4  := Col3;
Col3  := Col2;
Col2  := Col1;
Col1  := x;
Cycle := x;

That's pascal code.  That until line defines the condition that will stop repeating x=random(16), which are x not being in the [1..6,9--15] array, and x not being either Col1,2,3 or 4.  At least that's how I understand it, if I understood wrong please someone correct me.  FutureCow

• HelpEditor
• Prof. Inline
•      • • Posts: 680 Re: While not statement?
« Reply #3 on: 2010-Mar-01 »
You can group multiple if statements with the AND keyword.
Code: (glbasic) [Select]
X = RND(16)
WHILE X < 7 AND X >8 AND X <> COL1 etc

Compound if/while statements can lead to some time consuming bugs. I would suggest the following to test your code - combine all the separate conditions to be checked into one statement when you've got everything working.
Code: (glbasic) [Select]
DONE = 0
WHILE DONE = 0
X = RND(16)
IF X < 7
IF X > 8
IF X <> Col1
(etc)
DONE = 1     // This breaks out of the loop when all the conditions are satisfied
ENDIF
ENDIF
ENDIF

IF DONE = 0         // This block of code will get executed if all the conditions weren't matched
Col 4 = Col3
(etc)
ENDIF
WEND