0

I was studying some code I noticed the following function.

Obviously, it is a short form of something, I have never come across this.

What does the < 0 ? 0.003 : 0.001 do ? Can you explain in plain English? Thank you.

(_bird.physicsBody.velocity.dy < 0 ? 0.003 : 0.001)
Farshid Palad
  • 813
  • 1
  • 6
  • 7
  • If you are going to program in Objective-C and thus "C" (which is the base of Objective-C) you need to learn the language. There are many books and online references. Lookup "ternary" operator. Just like any other discipline you need to learn the tools. – zaph Jun 22 '14 at 16:44

1 Answers1

1

This code:

(_bird.physicsBody.velocity.dy < 0 ? 0.003 : 0.001)

is the same as:

if (_bird.physicsBody.velocity.dv < 0) {
    return 0.003;
} else {
    return 0.001;
}
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76