Andre Kostur wrote:

> desktop <(E-Mail Removed)> wrote in news:f3mgvl$med$(E-Mail Removed)-c.dk:

>

>>

>> Ok but what about this (assuming that there is no such thing as a

>> switch):

>>

>>

>> int k = 40;

>>

>> /* Case 1. */

>> if (k == 10) {

>> std::cout << "1\n";

>> } else

>> /* Case 2. */

>> if (k == 20) {

>> std::cout << "2\n";

>> } else

>> /* Case 3. */

>> if (k == 30) {

>> std::cout << "3\n";

>> } else

>> /* Case 4. */

>> if (k == 40) {

>> std::cout << "4\n";

>> }

>>

>>

>>

>> /* INSTEAD OF:*/

>>

>> /* Case 1: Only 1 element in the list. */

>> if (k == 10) {

>> std::cout << "1\n";

>> } else {

>> if (k == 20) {

>> std::cout << "2\n";

>> } else {

>> if (k == 30) {

>> std::cout << "3\n";

>> } else {

>> if (k == 40) {

>> std::cout << "4\n";

>> }

>> }

>> }

>> }

>

> Neither:

>

> if (k == 10)

> {

> std::cout << "1\n";

> }

> else if (k == 20)

> {

> std::cout << "2\n";

> }

> else if (k == 30)

> {

> std::cout << "3\n";

> }

> else if (k == 40)

> {

> std::cout << "4\n";

> }
For unsigned 'k':

std::cout << "01234"[k / 10 % 5] << "\n";

V

--

Please remove capital 'A's when replying by e-mail

I do not respond to top-posted replies, please don't ask