Select/Case formatting

BlitzMax Forums/BlitzMax Beginners Area/Select/Case formatting

This is another thing I've never seen covered: how do I make a Select/Case statement easier to read?

For example:

Select Lop
Case 16
IncLine=2
xPos=0
dummy = true
Case 24
IncLine=3
xPos=0
dummy = false
End Select

I'd like to see all of these small items on one line, if possible. Like this:

Select Lop
Case 16 : IncLine=2 : xPos=1 : dummy=true
Case 24 : IncLine=3 : xPos=0 : dummy=false
End Select

What's the proper formatting? Obviously the colons don't work under BlitzMax.

Use ;

:)

Holy crap I feel stupid.

For some reason I was still equating ; with the old commenting system (as in, don't use for anything except comments).

Thanks again, Amon.

I prefer using tabs eg:

Select x
	Case 1
		i = 10
	Case 2
		j = 20
	Case 3
		k = 30
End Select


Slightly O/T, also if you didnt know you can use .. to continue a line eg:

If	x = 1 And .. 
	y = 2 And ..
	z = 3 ..
Then
	i = 10
End If


Which is great for really long if statements...

I use tabs like the revills too.

Hi, therevils

I've used your method in the past for certain things, I just sometimes am tired of seeing a lot of vertical lines going down my code like a=2 so I like to group them all together. So here's what the code now looks like:

Select Lop
Case 8 ;IncLine=1 ;xPos=0
Case 16 ;IncLine=2 ;xPos=0
Case 24 ;IncLine=3 ;xPos=0
Case 32 ;IncLine=4 ;xPos=0
Case 40 ;IncLine=5 ;xPos=0
Case 48 ;IncLine=6 ;xPos=0
Case 56 ;IncLine=7 ;xPos=0
Case 64 ;IncLine=8 ;xPos=0
End Select

A lot more compact, and I still find it quite readable.

and very worthless as you do repetitive if statements for something solved by a single if ...
if Lop mod 8 = 0
  IncLine = Lop / 8
  xPos = 0
endif


If you don't indent, you're nuts.

Apart from Dreamora's math solution, I try to avoid Select-cases like these when they have a lot of similar/repetitive statements in each Case.
The xPos=0 could well have been outside the Select-Case structure. Another thing to try is to use look-up tables, in use that instead of a Select-Case structure.

A golden rule in programming: "can it be done shorter/more compact, then it's usually better to do so". Even if the performance gain is minimal, the readability may improve as well as flexibility (and thus reusability), which will reward you in the long run.

Not needfully (thought for general it surely is true). if it is only reset in those cases ( assume thats a textlength - multiline splitter ), it must be within actually

As for the xPos=0, this is just dummy code. And also, my code is ALWAYS indented.

Thanks for the extra help, but it's unneeded LOL

Cheers,
Don

put your code in [ code] [/ code] tags