[ENGLISH VERSION] Loops

Hey, are you ok?

As fundamental part of the programming languages, the loops allow us repeat a wide range of commands, saving work/time, being an important tool for all programmer.

Ruby offers not many and today we’re going to talk about them: while and until.


WHILE

Well known, while does something “while” it’s codition is satisfied.

y = 1

while y <= 10
  puts y
  y += 1
end

Out:

1
2
3
4
5
6
7
8
9
10

The while loop, like all others, accepts the break command, but be careful – you don’t really need it, if you make a good loop logic.


UNTIL

The until loop executs a set of commands “until” – Ruby is such a human language – it’s condition is satisfied, the opposite of while.

a = 1

until a >= 10
  puts a
  a += 1
end

Out:

1
2
3
4
5
6
7
8
9

So, did you like this post? Is something missing? Tell on the comments!

It was so good to see you here! Bye!

ENGloops1

Anúncios

Um comentário sobre “[ENGLISH VERSION] Loops

Diga alguma coisa ... suas dúvidas quem sabe!

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s