Skip to main content
deleted 69 characters in body
Source Link
trejder
  • 2.4k
  • 3
  • 22
  • 39

Who decided, and basing (and based on what concepts,) that switch construction (in many languages) has to be like it is? Why do we have to use break in each statement? 

Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

(I've noticednoticed this construction in PHP and JS, butJS; there are probably many other languages that use itusing this)

If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said, that break prevents the execution of the block following the current one. But, does someone really run into the situation, where there was any need for execution of the current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Who decided, and basing on what concepts, that switch construction (in many languages) has to be like it is? Why do we have to use break in each statement? Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

(I've noticed this construction in PHP and JS, but there are probably many other languages that use it)

If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said, that break prevents the execution of the block following the current one. But, does someone really run into the situation, where there was any need for execution of the current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Who decided (and based on what concepts) that switch construction (in many languages) has to use break in each statement? 

Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

(noticed this in PHP and JS; there are probably many other languages using this)

If switch is an alternative of if, why we can't use the same construction as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said that break prevents the execution of the block following the current one. But, does someone really run into the situation, where there was any need for execution of the current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Who decided, and basing on what concepts, that switch construction (in many languages) has to be, like it is? Why do we have to use break in each statement? Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

(I've noticed this construction in PHP and JS, but there are probably many other languages that usesuse it)

If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said, that break prevents the execution of a blocksthe block following the current one. But, does someone really run into the situation, where there was any need for execution of the current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Who decided, and basing on what concepts, that switch construction (in many languages) has to be, like it is? Why do we have to use break in each statement? Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

(I've noticed this construction in PHP and JS, but there are probably many other languages that uses it)

If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said, that break prevents execution of a blocks following current one. But, does someone really run into situation, where there was any need for execution of current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Who decided, and basing on what concepts, that switch construction (in many languages) has to be like it is? Why do we have to use break in each statement? Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

(I've noticed this construction in PHP and JS, but there are probably many other languages that use it)

If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said, that break prevents the execution of the block following the current one. But, does someone really run into the situation, where there was any need for execution of the current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Question Protected by gnat
added 1 character in body; edited title
Source Link
trejder
  • 2.4k
  • 3
  • 22
  • 39

Why do we have to use break in switch?

Who decided, and basing on what concepts, that switch construction (in many languages) has to be, like it is? Why do we have to use break in each statement? Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

I've(I've noticed this construction in PHP and JS, but there are probably many other languages that uses it.)

If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said, that break prevents execution of a blocks following current one. But, does someone really run into situation, where there was any need for execution of current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Why do we have to use break in switch

Who decided, and basing on what concepts, that switch construction (in many languages) has to be, like it is? Why do we have to use break in each statement? Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

I've noticed this construction in PHP and JS, but there are probably many other languages that uses it.

If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said, that break prevents execution of a blocks following current one. But, does someone really run into situation, where there was any need for execution of current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Why do we have to use break in switch?

Who decided, and basing on what concepts, that switch construction (in many languages) has to be, like it is? Why do we have to use break in each statement? Why do we have to write something like this:

switch(a) { case 1: result = 'one'; break; case 2: result = 'two'; break; default: result = 'not determined'; break; } 

(I've noticed this construction in PHP and JS, but there are probably many other languages that uses it)

If switch is an alternative of if, why we can't use the same construction for switch, as for if? I.e.:

switch(a) { case 1: { result = 'one'; } case 2: { result = 'two'; } default: { result = 'not determined'; } } 

It is said, that break prevents execution of a blocks following current one. But, does someone really run into situation, where there was any need for execution of current block and following ones? I didn't. For me, break is always there. In every block. In every code.

Tweeted twitter.com/#!/StackProgrammer/status/240418652380352512
edited body
Source Link
gnat
  • 20.5k
  • 29
  • 117
  • 310
Loading
Source Link
trejder
  • 2.4k
  • 3
  • 22
  • 39
Loading