Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Substitute For An "and" Statement Inside Of An If?


  • Please log in to reply
8 replies to this topic

#1 tavichh

tavichh

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts
  • Location:Delaware
  • Programming Language:C#
  • Learning:C++, PHP, JavaScript

Posted 14 June 2012 - 09:59 AM

I could not find a an and statement anywhere on the reference site, so I am assuming there is none. What would be the if statement if I wanted two conditions
Like in english words, it will be:

If blank = awesome and theotherblank = superawesome

How would that be done?
  • 0
Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)

#2 Momerath

Momerath

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 282 posts
  • Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Visual Basic .NET, Pascal, Ada, Assembly, Fortran, Scheme
  • Learning:Others

Posted 14 June 2012 - 11:03 AM

if (blank == awesome && theotherblank == superawesome) {

    // stuff here

}

  • 1

#3 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 14 June 2012 - 11:04 AM

In C#, it's the && operator.

if ((a == <img src='http://forum.codecall.net/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' /> && (x == y)) {

}

  • 1

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#4 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 14 June 2012 - 11:15 AM

in which language you don't find an "and" ?
if you are talking c# the and is the && and the or is the || so, also take into account that in many languages string comparisson comes with functions, or operators if you are programming shell
  • 1

#5 tavichh

tavichh

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts
  • Location:Delaware
  • Programming Language:C#
  • Learning:C++, PHP, JavaScript

Posted 14 June 2012 - 05:24 PM

in which language you don't find an "and" ?


I dunno :P

Thank you guys for helping me out on this
  • 0
Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)

#6 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 14 June 2012 - 09:38 PM

You may see these normally referred to as boolean or logical operators.

Bitwise operators are similar, usually with one symbol (&, |, ^, ~ ..) and are for manipulation of bits.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#7 Yonatan

Yonatan

    CC Regular

  • Member
  • PipPipPip
  • 37 posts
  • Location:Israel
  • Programming Language:C, Java, C++, C#, JavaScript, PL/SQL, Visual Basic .NET
  • Learning:Python, JavaScript

Posted 19 June 2012 - 02:00 PM

Please notice that & and && are different,
& is a simple conjunction.
&& will stop test in case of false.

So for example if I have the string parameter and I want to check:
if(parameter==null) and if(parameter.contains("apple"))

It will be incorrect to use & because you cant test the second condition if parameter is null.
so I will do:
if(parameter==null && parameter.contains("apple"))
      //do something

  • 1

#8 tavichh

tavichh

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts
  • Location:Delaware
  • Programming Language:C#
  • Learning:C++, PHP, JavaScript

Posted 19 June 2012 - 02:49 PM

Thanks.
  • 0
Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)

#9 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 20 June 2012 - 02:13 AM

Since you didn't know the language, what if it's Pascal?

In pascal this:

Like in english words, it will be:

If blank = awesome and theotherblank = superawesome


would become:

If (blank=awesome) and (theotherblank=superawesome) then
begin
  // do your stuff
end;

  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download