Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #10388

Re: Skip case is not expected

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: Skip case is not expected
Date 2012-01-19 15:34 +0200
Organization A noiseless patient Spider
Message-ID <jf964t$7fa$1@dont-email.me> (permalink)
References <aa1b4e7f-7175-476f-b114-f52dbad34b4e@l19g2000yqj.googlegroups.com> <c968f646-614f-4c8d-bdeb-819738fc16cf@18g2000yqe.googlegroups.com>

Show all headers | View raw


2012-01-19 15:11, Captain Paralytic wrote:

>>   var i = 6; switch (i) {
>>          case i<  10:
[...]
> Well what is wrong is that you are making up your own syntax.

Technically, the syntax is correct. This is a matter of misunderstanding 
the meanings (semantics).

> switch(i) Says examine the value of i
> case value The values need to be specific values that the value of i
> can be compared with.

So what happens here is that the expressions in case clauses are 
evaluated, and whether they evaluate to true or false, none of them 
matches the value of i.

> Try replacing switch(i) with switch(true) and put your logical
> expressions in brackets.

Using switch(true) is possible but does not make the code particularly 
readable. Good old if statements are easier to read.

I don't see why the expressions would need to be put in brackets, or in 
parentheses, in case clauses.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Skip case is not expected Archos <raul.san@sent.com> - 2012-01-19 04:46 -0800
  Re: Skip case is not expected Captain Paralytic <paul_lautman@yahoo.com> - 2012-01-19 05:11 -0800
    Re: Skip case is not expected "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-01-19 15:34 +0200
  Re: Skip case is not expected Richard Cornford <Richard@litotes.demon.co.uk> - 2012-01-19 05:36 -0800

csiph-web