Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do these inline IFs exist?
#1
For efficiency, I must instead of this,

Code:
FOR I% = 1 to 50
IF a% = b% THEN PRINT "BOO"
PRINT "BOO2"
NEXT I%

Make this:

Code:
IF a% = b% THEN
FOR I% = 1 to 50
PRINT "BOO"
PRINT "BOO2"
NEXT I%
ELSE
FOR I% = 1 to 50
PRINT "BOO2"
NEXT I%

When I have more than one such IF, the amount of copying/pasting increases by 2. (2^n) So it's very inconvenient.

Does any programming language in existence support an inline IF, that is, one that has code similar to the first example, but behaves like the second? Smile
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#2
Nope AFAIK. It would imply that the compiler is intelligent. But those GCC ports are like the evil, they make many optimizations and maybe such is included.

Anyhow, haven't you ever listened/read the famous computer science rule which says "speed vs. memory"?
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
I know about that rule.

But that doesn't mean that the compiler can't do it.

I'm going to try to make a qb reprocessor for qb programs for this very important optimization.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#4
I didn't mean the compiler can't do it.

Good look with your attempt, but it will be hard stuff. You need to parse QB!
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
I would use this method because there is only one if statement as it's not inside the For-Next loop:
Code:
IF a% = b% THEN

FOR i% = 0 TO 50

  PRINT "B00"
  PRINT "B002"

NEXT i%

ELSE

FOR i%= 0 TO 50

  PRINT "B002"

NEXT i%

END IF

Or did I missunderstand something???
B 4 EVER
Reply
#6
Ok, here's what I came up with for ideas.

1) Use the command IIF instead of the regular IF. (or, have a comment like "'inline" right before the IF statement. Yeah..

2) Create a command block like this:

'BLOCK [name]
'stuff, such as:
for i = 1 to 10
next i
'END BLOCK

Ok, now the compiler does this:
1) Find all blocks.
2) Find all inline IFs in each block.
3) Duplicate each block for as many times as necessary while creating the appropriate IF structure.

Ok, now code for that is a different story.. :barf:

EDIT: Yessir you did Ak00ma. There should be a way to do this more automatic-like. The more IFs you move out of the loop, the more you have to duplicate stuff..
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)