Ruby Until Loop

Ruby Until Loop

The Ruby Until loop Statement. The Until loop executes ruby code while condition is false.

Until loop syntax

until condition do
	-- Ruby code 
end
--or
begin
	-- Ruby code 
end until condition

Until loop example 1

$x = 1
$y = 3

until $x > $y do
   puts("The value of x = #$x" )
   $x +=1
end

Output

The value of x = 1

The value of x = 2

The value of x = 3

Until loop example 2

$x = 1
$y = 3

begin
   puts("The value of x = #$x" )
   $x +=1
end until $x > $y  

Output

The value of x = 1

The value of x = 2

The value of x = 3