[RUBY] How to achieve paiza rank C (times method)

Introduction

*** paiza How can I achieve Rank C ***? I explained the guideline.

Premise

Since the author is mainly learning Ruby, I will explain it in Ruby.

Run

To aim for C rank, you need to master the repetition conditions. I often use the times method.


t = gets.to_i

t.times do
  puts "hello!"
end

If you execute the above program, hello! Will be output as many times as you enter. If you apply it, you can also do the following.


t = gets.to_i
i = 1

t.times do
  puts i
  i += 1
end

If you execute the above program, integers from 1 to the number will be output in order. Arrays can also be used.


t = gets.to_i
num = []
i = 1

t.times do
  num << i
  i += 1
end

If you run this program, you will get an array of [1, 2, 3,…, i].

In order to aim for paiza rank C, it is first necessary to master this times method.

Recommended Posts

How to achieve paiza rank C (times method)
How to achieve paiza rank D
[Java] How to play rock-paper-scissors (equivalent to paiza rank A)
How to create a method
How to use the link_to method
How to use the include? method
How to use the form_with method
[Java] How to use join method
How to use Ruby inject method
[Java] How to compare with equals method
How to use submit method (Java Silver)
[Rails] How to use the map method
[Java] How to use the toString () method
How to have params in link_to method
[Rails] How to use helper method, confimartion
How to achieve file upload with Feign
How to run Blazor (C #) with Docker
[Ruby] How to use gsub method and sub method
How to use the replace () method (Java Silver)
[Ruby basics] How to use the slice method
Javaer tries to summarize how to write properties in C #
[Java] How to use compareTo method of Date class
[rails] How to use devise helper method before_action: authenticate_user!
paiza Ruby What I did to become B rank
How to add characters to display when using link_to method
How to mock a super method call in PowerMock
How to create and execute method, Proc, Method class objects