Let's say I have .tex file which is a set of problems and solutions, of which I want to make two pdf files, one which includes the solutions and one which doesn't. so I need to build the .tex file under two different modes, and specify that parts of the document be ignored under one of the modes.

This is something common in programming context. e.g. in C++ i can code

Over time I have used all the options (and stayed away from xifthen due to comments at link regarding that this package is obsolete), but tend to gravitate to \ifdefined when doing quick tests, and use etoolbox approach for more longer term solutions for on/off conditions, and the xstring approach when there are more conditions to consider.

As @Seamus mentions there is a \newif built in, but I have tended to avoid that as I did not like the syntax and had to look it up every time, but that is just a personal preference

[Purpose:] selectively in/exclude pieces of text: the user can define new
comment versions, and each is controlled separately.
Special comments can be defined where the user specifies the
action that is to be taken with each comment line.

The other answers address the general case. In relation to the specific problem that you describe in which you want to typeset Questions and Answers, you might like to consider the answers package which does all of the hard work for you.

MWE

I've set up a problem and shortsolution environment in what follows- the answers package writes the shortsolution to the file shortsolutions.tex, which is then included at the end of the document.

For code

A normal conditional method in TeX is to use \newif\iffoo and use \iffoo .. \else ... \fi to do the test, use \footrue and \foofalse to change the state.

This is the basic conditional mechanism in both Plain TeX and LaTeX, and is used by most LaTeX packages.

It is not the LaTeX syntax, and doesn't support complex bool expressions. Then packages ifthen/xifthen, etoolbox, expl3 etc. can be used to support more complex conditions. I suggest etoolbox or expl3.

For text

Those conditions above are for general material, mostly macros and short text. However, they are not robust sometimes: you can't use unbalanced \else, \fi, \ifXXX in the branches, for very long text it may cause surprising errors. Then you can use comment, xcomment, tagging packages for longer text (but not for macros). They work in a verbatim way.