Page 1 of 1

PB Survival guide A must read!!!

Posted: Sun Aug 21, 2016 6:07 pm
by Zebuddi123
Hi to all Just looking through Blueznl Survival Guide and came across C shorthand stuff and was just looking how i could apply that shorthand. How about a multi variable for loop ?

The Idea is to use 3 possible iteration integers based on the result of 2 variables a,b with the 3 possible results being based on = < >

May come in useful for some, I quite like the idea! Thanks Blueznl :)

Updated as a macro.

Because it uses bitwise OR more than one result would give the wrong result. So the Operators are built into the macro with = < > supported.

Code: Select all

a = 3 : b = 23

;if a = b loop 30   if a < b loop 120  if a > b loop 60

Macro VarLoop(Var_A, Var_b,  Multiplier_integer, Equals_Iteration, LessThan_Iteration, GeaterThan_Iteration)
	(  (Multiplier_Integer * (Bool( Var_A = Var_B) * Equals_Iteration)) |  (Multiplier_Integer * (Bool( Var_A < Var_B) * LessThan_Iteration))  |  (Multiplier_Integer * (Bool( Var_A > Var_B) * GeaterThan_Iteration))   )
EndMacro 

CallDebugger

For i = 1 To VarLoop(a, b, 6, 20, 10, 5) 
	Debug i
Next
Zebuddi. :)

Re: PB Survival guide A must read!!!

Posted: Mon Aug 22, 2016 7:50 pm
by Derren
What is the multiplier (6) needed for?
I was a bit confused, because the comment doesn't predict the outcome.
The way your code now works is:
if a = b loop 120 (20*6)
if a < b loop 60 (10*6)
if a > b loop 30 (5*6)

Re: PB Survival guide A must read!!!

Posted: Mon Aug 22, 2016 8:04 pm
by jack
why would you want to write such obfuscated code?
it's not worth it unless you are entering an obfuscated code contest.

Re: PB Survival guide A must read!!!

Posted: Mon Aug 22, 2016 11:08 pm
by netmaestro
No offense, and thanks blueznl for your work on the survival guide, seriously. -however- I don't see how this snippet would help someone survive the learning curve for PB. My eyes are still crossed from trying to read that macro :lol:

Re: PB Survival guide A must read!!!

Posted: Tue Aug 23, 2016 7:30 am
by TI-994A
Derren wrote:What is the multiplier (6) needed for?
Exactly; what is the multiplier for?

It seems to work without it, and appears more readable as well:

Code: Select all

;if a = b loop 30   if a < b loop 120  if a > b loop 60

a = 1 : b = 2
  
For i = 1 To (Bool(a = b) * 30) | (Bool(a < b) * 120) | (Bool(a > b) * 60)
  Debug i
Next