User forums > Using Code::Blocks

code folding switch statements

(1/1)

Story:
How can I fold an individual case of a switch statement? I don't see any option to do so.
I am using version 10.05 on Windows 7.

Freem:
I don't think it's possible.
If you really need it, you can always surround the bloc of code with '{' and '}'.
I have never seen it in other code, but one day I've tried it and it compile (ok, I didn't try it into a case statement. By the way, I really rarely use case statements, and they often just call a function, because the code if often reused later)

PS: And I don't think it could become, as there are is way to know the end of the bloc: break statements are not mandatory, so you can say that "case 1:" just imply to run something AND "case 2:".
This is why you probably never see fold in switch cases in an editor made to write C/C++ code.
(some can do, as notepad++ in certain conditions, because it fall on a indent style fold when it don't know the language.)

MortenMacFly:

--- Quote from: Freem on July 28, 2011, 10:32:15 am ---If you really need it, you can always surround the bloc of code with '{' and '}'.

--- End quote ---
To be precise, the following snippet does the trick:

--- Code: ---  switch (foo)
  {
    case bar1:
    { //{
      Func1();
      break;
    } //}
    case bar2:
    { //{
      Func2();
      break;
    } //}
  }

--- End code ---

Navigation

[0] Message Index

Go to full version