News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

code folding switch statements

Started by Story, July 28, 2011, 03:51:56 AM

Previous topic - Next topic

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

#1
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 '}'.
To be precise, the following snippet does the trick:
  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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]