• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

What does || exactly mean?

971
Posts
7
Years
  • Age 21
  • Seen Nov 28, 2022
I'm trying to understand coding in general and I think I know all of the symbols, but this one I'm still not exactly sure about. I googled it quickly but couldn't really find much since google doesn't take "||" in account when searching.
What I thought it meant from the bits of code I read I concluded it would be something like "and", "and if" or perhaps "or if". If someone could answer this with certainty, I'd be able to use it and understand what those big "if"'s that include them mean.

I have two small examples here from PokeBattle_MoveEffects:

Code:
    if attacker.status==0 ||
      (attacker.status==PBStatuses::PARALYSIS && !opponent.pbCanParalyze?(attacker,false,self)) ||
      (attacker.status==PBStatuses::SLEEP && !opponent.pbCanSleep?(attacker,false,self)) ||
      (attacker.status==PBStatuses::POISON && !opponent.pbCanPoison?(attacker,false,self)) ||
      (attacker.status==PBStatuses::BURN && !opponent.pbCanBurn?(attacker,false,self)) ||
      (attacker.status==PBStatuses::FROZEN && !opponent.pbCanFreeze?(attacker,false,self))
      @battle.pbDisplay(_INTL("But it failed!"))
      return -1
    end
Code:
    if attacker.gender==2 || opponent.gender==2 || attacker.gender==opponent.gender
 
971
Posts
7
Years
  • Age 21
  • Seen Nov 28, 2022
https://stackoverflow.com/questions/2083112/difference-between-or-and-in-ruby
An important note as to why || is used over explicitly saying 'or' is operator precedence

For possible future reference, http://symbolhound.com/ is a good search engine that supports special characters. It's very helpful for specific coding questions.

Thanks for your help. I've also been learning Ruby (programming language Essentials uses) the last few days to help me out in the future. I did encounter || meaning or there, but didn't know about precedences with && || and !. I'll be aware of that in the future.
 
Last edited:
Back
Top