🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.c++
Article #168

Re: Duda IF ?

#168
From: josedaniel.garcia
Date: Mon, 24 Aug 2009 08:42
39 lines
2412 bytes
No entiendo bien la pregunta. ¿Sintácticamente correcto? ¿Correcto
desde el punto de vista de estilo?

Primero. La segunda condición debería ser (var==7) ¿verdad?

Segundo. Si se quiere comparar con muchos valores parece un poco
largo.

Alternativa 1:

switch (var) {
  case 3:
  case 7:
  case 15:
	std::cout << "El valor es 3, 7 o 15" << std::endl;
}

Alternativa 2: Personalmente me gusta más

int v[] = {3, 7, 15};
int * end = v + sizeof(v)/sizeof(v[0]);
if ( end != std::find(v, end, var)) {
	std::cout << "El valor es ";
	std::copy(v, end, std::ostream_iterator<int>(std::cout, " "));
}


On 23 ago, 13:06, ELfun <virtial.di...@gmail.com> wrote:
> Hola, os agradecería que me comentaseis si es correcto esta forma de
> usar IF
>
> if ((var ==3) || (var7 ==7) || (var ==15)){
>  printf ("La variable es 3 , 7 o 15");
>
>
>
> }- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -
Technical Details
Message-ID: <2c2ca95b-9d5f-48c7-8104-a4294280f02d@z24g2000yqb.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!z24g2000yqb.googlegroups.com!not-for-mail
References: <ba8c3ca3-0dd7-4a24-8633-4737b0b6c25f@k30g2000yqf.googlegroups.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: d2efa0cfdc,706742b0d1c7e367
X-Google-Attributes: gidd2efa0cfdc,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!z24g2000yqb.googlegroups.com!not-for-mail
From: "josedaniel.garcia" <josedaniel.garcia.uc3m@gmail.com>
Newsgroups: es.comp.lenguajes.c++
Subject: Re: Duda IF ?
Date: Mon, 24 Aug 2009 01:42:05 -0700 (PDT)
Organization: http://groups.google.com
Lines: 40
Message-ID: <2c2ca95b-9d5f-48c7-8104-a4294280f02d@z24g2000yqb.googlegroups.com>
References: <ba8c3ca3-0dd7-4a24-8633-4737b0b6c25f@k30g2000yqf.googlegroups.com>
NNTP-Posting-Host: 163.117.148.211
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1251103325 17394 127.0.0.1 (24 Aug 2009 08:42:05 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 24 Aug 2009 08:42:05 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: z24g2000yqb.googlegroups.com; posting-host=163.117.148.211; 
 posting-account=9JbdoAoAAABBMcTZCBn244HTTxTuDMJb
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 
 Trident/4.0; GTB6; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0;
 .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2;
 OfficeLiveConnector.1.3; OfficeLivePatch.0.0),gzip(gfe),gzip(gfe)