Syntax

Ruby If / Elsif / Else Syntax

In Ruby, if / elsif / else: runs code depending on a condition — if x > 0 ... elsif x == 0 ... else ... end

Quick Answer

Syntax
if x > 0 ... elsif x == 0 ... else ... end
RubySyntax

If / Elsif / Else

Code example
if x > 0 ... elsif x == 0 ... else ... end

Runs code depending on a condition.

Learn More

How to if / elsif / else in Ruby

  1. Open your Ruby file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Ruby If / Elsif / Else Syntax

Use if x > 0 ... elsif x == 0 ... else ... end.

Related Syntax References

Frequently asked questions

What is the Ruby syntax for if / elsif / else?

Use this pattern: if x > 0 ... elsif x == 0 ... else ... end

Can I copy this Ruby code example?

Yes. Use Copy code and adapt the example to your program.

Is this Ruby syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify