Conditional Branching (AREV Specific)
At 21 OCT 1999 01:39:19PM Dale Walker (MagCorp) wrote:
Does anyone know how deep conditional branching can go?
I'm using loops, case statements, if .. then else.. nested in each other.
Thanks,
Dale
At 21 OCT 1999 04:31PM Victor Engel wrote:
Well, at compile time, these get converted into labels, ifs, and gotos. I doubt if there is a limit other than number of variables available. The real question, though, is whether you are going to add meatballs to the spaghetti.
At 21 OCT 1999 04:35PM Dale Walker wrote:
That depends on the ingredients in the meatball, whether the spaghetti has veggies in it and whats in the sauce to say nothing of the cheese.
Dale
At 21 OCT 1999 05:45PM Steve Smith wrote:
If you are using many conditions for selection, then one technique is to assign a power of two to each condition, and use a case statement. eg.
CARTYPE=0
IF CAR=RED" THEN CARTYPE=CARTYPE + 1
IF CAR=BLUE" THEN CARTYPE=CARTYPE + 2
IF CAR=PINK" THEN CARTYPE=CARTYPE + 4
IF CAR=AUTO" THEN CARTYPE=CARTYPE + 8
That way you're only maintaining one integer for the attributes
You can then test/branch using the BITAND command
IF BITAND(CARTYPE,1) THEN PRINT "Car is Red"
IF BITAND(CARTYPE,2) THEN PRINT "Car is Blue"
IF BITAND(CARTYPE,4) THEN PRINT "Car is Pink"
IF BITAND(CARTYPE,8) THEN PRINT "Car is Auto"
You can also readily test for combinations
IF BITAND(CARTYPE,12) THEN PRINT "Car is a Pink Auto"
Effectively you're using one bit for each attribute, turning it
on or off in a binary sense by adding to CARTYPE. This is probably
the most efficient use of storage and variables for complicated problems. Beware of the upper limits of the integer math in AREV, though - the scientific notation is naturally too coarse to use
here.
Steve
At 22 OCT 1999 09:10AM Dale Walker (MagCorp) wrote:
I use case statements very often and embed them in loops, for statements, and within them I use if then else statements. I understand what you are saying. I was wondering how "deep" I can go.
Is there a limit? The reason that I ask, is that about seven layers deep I need to know what values are being used so I can troubleshoot my routines. I use generally the following format:
PRINT "THIS IS variable1: ":variable1
etc.
PRINT "OK? ":; INPUT Q,2 ; IF Q=N' THEN STOP
This way I can allow the execution of the program after briefly looking at the data.
Thanks,
Dale
At 24 OCT 1999 02:49AM Steve Smith wrote:
As Victor said, there is no real limit (until you get about 1000 conditions deep).