I know there are all kinds of semantic problems with the following and such a construct is easily enacted by using more robust coding methods, but I just wondered what others made of the following?
a=1
If a = 1
For j = 1 To 10
Else
For j = 1 To 5
EndIf
Debug j
Next
Part of me thinks that this should be allowed (not just in Purebasic) even though, by anyone's standards, it would be extremely poor coding practice, and yet another part of me turns it's nose up in disgust!
Any thoughts?
(Again, no offence intended, but no one needs to point out the reasons why the above does not compile! )
I may look like a mule, but I'm not a complete ass.
Trond wrote:So where do you want the jump at the Next keyword to jump?
I'm not saying that I think this is necessarily a good idea; I just found myself coding a loop with variable start and end indexes etc. and experimented with this just to see if it would compile, just out of interest! Thankfully it didn't compile, but it got me thinking!
Anyhow, the 'next' would necessarily have to jump to the statement immediately following the EndIf.
I know it's kind of a barmy notion!
I may look like a mule, but I'm not a complete ass.
srod wrote:Part of me thinks that this should be allowed (not just in Purebasic) even though, by anyone's standards, it would be extremely poor coding practice, and yet another part of me turns it's nose up in disgust!
Anyone who concieves of such a construct should be flogged 'round the fleet, keelhauled and fed piecemeal to the sharks. Then he should really be punished (forced to code in .net for a year)
srod wrote:Anyhow, the 'next' would necessarily have to jump to the statement immediately following the EndIf.
That would make an infinite loop.
It would just be a loop of 5 or 10, not infinite.
Not if it jumps to the statement just after the EndIf. Then the comparision at the start of the loop is never reached.
Srod: Try to code what you want with if and goto only (that's the kind of constructs the compiler has available to compile the loop into) and you'll see that there will be a problem with the Next.
@minirop: as stated, coding around the issue is not a problem, I was just thinking aloud! Actually, the fact that we can code around the problem proves that such constructs can be added to a language; even assembly, although a corresponding LOOP statement would need to be embedded within an extra conditional. It's just a question of whether such things should even be considered?
@netmaestro: yee-owch! That's awful, only a sadist would threaten someone with .net!
I may look like a mule, but I'm not a complete ass.
netmaestro wrote:Anyone who concieves of such a construct should be flogged 'round the fleet, keelhauled and fed piecemeal to the sharks. Then he should really be punished (forced to code in .net for a year)
The compiler would need to ensure that ECX was preserved through a procedure call.
Now your second snippet is not an 'srod' loop as you've altered the loop counter from a to c. I think the compiler would implode with this piece of code!
I may look like a mule, but I'm not a complete ass.