Feature request: C Switch statement

General FreeBASIC programming questions.
Post Reply
ShawnLG
Posts: 142
Joined: Dec 25, 2008 20:21

Feature request: C Switch statement

Post by ShawnLG »

Can the C Switch statement be added to FreeBASIC? It has different functionality than the Select Case statement. Such as optional Break from Case block.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Feature request: C Switch statement

Post by dodicat »

You can somewhat simulate switch.

Code: Select all

#define nobreak(n)  end select: select case n


Dim As Integer x=6
Print "Where is ";x;" ?"

Select Case x

Case 6
      Print 6
      nobreak(x)
      
Case 2 To 7
      Print 2;" to ";7
      nobreak(x)
      
Case 9 To 14
      Print 9;" to ";14
      nobreak(x)
      
Case 5 To 7
      Print 5;" to ";7
      nobreak(x)
      
Case  12
      Print 12
      nobreak(x)
      
Case Else
      print "else ";x
      
End Select
Sleep

 
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Feature request: C Switch statement

Post by caseih »

It's very interesting to see someone request a C-style switch statement. Especially because not that long ago we had a discussion (I think it was here) about how bizarre and problematic the C switch construct is with it's default fall-through behavior (as eevblog says, a trap for young players). For someone coming from assembly, the C switch construct is no doubt appealing for making certain kinds of control structures. I am personally a fan of it. However I don't think it has a place in FreeBASIC to be honest.

What would be your use case for this feature?
Post Reply