Skip to content

Latest commit

 

History

History
48 lines (38 loc) · 530 Bytes

loops_in_ruby.md

File metadata and controls

48 lines (38 loc) · 530 Bytes

Loops

1. While Loop

#!/usr/bin/ruby
$i = 0
$num = 5

while $i < $num  do
   puts("Inside the loop i = #$i" )
   $i +=1
end

2. Do-While Loop

#!/usr/bin/ruby
$i = 0
$num = 5
begin
   puts("Inside the loop i = #$i" )
   $i +=1
end while $i < $num

3. While-Do Loop

#!/usr/bin/ruby

$i = 0
$num = 5

until $i > $num  do
   puts("Inside the loop i = #$i" )
   $i +=1;
end

4. For Loop

#!/usr/bin/ruby

for i in 0..5
   puts "Value of local variable is #{i}"
end