startuprob
startuprob

Reputation: 1915

What does '||' mean in objective C?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

    // Return YES if incoming orientation is Portrait
    // or either of the Landscapes, otherwise, return NO
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait) || UIInterfaceOrientationIsLandscape(toInterfaceOrientation);

}

What does the '||' mean here?

Upvotes: 1

Views: 174

Answers (9)

BobLong
BobLong

Reputation: 1

If UIInterfaceOrientationPortrait is equal to toInterfaceOrientation then it will return true, otherwise it will return the value of UIInterfaceOrientationIsLandscape(toInterfaceOrientation), which may be true or false.

Upvotes: 0

alexblum
alexblum

Reputation: 2238

Logical operator OR. See here

Upvotes: 0

Set
Set

Reputation: 58

Perhaps it means something different in Objective C, but in C, C++, and Java the || operator is logical OR.

Upvotes: 0

Patrick Perini
Patrick Perini

Reputation: 22633

In most programming languages (notable exceptions: Python, Ruby, etc.) || is the logical "OR" operator.

See also == (equals), != (does not equal), and && (and).

Upvotes: 0

shanethehat
shanethehat

Reputation: 15570

the function wil return a Boolean true if toInterfaceOrientation == UIInterfaceOrientationPortrait OR UIInterfaceOrientationIsLandscape() returns true.

Upvotes: 0

LukeH
LukeH

Reputation: 269408

It's a short-circuiting logical OR.

It returns true if either toInterfaceOrientation == UIInterfaceOrientationPortrait or UIInterfaceOrientationIsLandscape(toInterfaceOrientation), but the second operand is only evaluated if/when the first operand is false.

Upvotes: 1

Bill Burgess
Bill Burgess

Reputation: 14154

It means OR. Just the way Obj-C uses it.

|| = OR && = AND

Upvotes: 0

Vladimir
Vladimir

Reputation: 170839

|| is a logic 'or' operation - it returns true if at least one of its operands is true.

Moreover, if its first operand evaluates to true it returns true without evaluating its second operand.

Upvotes: 1

Daniel Dickison
Daniel Dickison

Reputation: 21882

Same thing as the C || operator: logical or.

Upvotes: 9

Related Questions