Author Topic: code folding switch statements  (Read 8874 times)

Offline Story

  • Single posting newcomer
  • *
  • Posts: 9
code folding switch statements
« on: July 28, 2011, 03:51:56 am »
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.

Offline Freem

  • Almost regular
  • **
  • Posts: 218
Re: code folding switch statements
« Reply #1 on: July 28, 2011, 10:32:15 am »
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.)
« Last Edit: July 28, 2011, 10:36:36 am by Freem »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: code folding switch statements
« Reply #2 on: July 28, 2011, 03:12:35 pm »
If you really need it, you can always surround the bloc of code with '{' and '}'.
To be precise, the following snippet does the trick:
Code
  switch (foo)
  {
    case bar1:
    { //{
      Func1();
      break;
    } //}
    case bar2:
    { //{
      Func2();
      break;
    } //}
  }
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ