Hey help me plz I can't find this on the Net #2 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Hey help me plz I can't find this on the Net #2

So in the Pascal language you can do the cycle so many times you want by typing this: s:=0; #first we enter the value of i; read i; #now we setup the cycle for it: for i:=1 to n do inc(s); write(s); end. #e.g. I=5 and s increments 5 times. So what I want to do? in Ruby it must be look ike this gets i for i in 1..n i+=1 I think I should recall the Ruby basics to understand how "for" cycle is working.

16th Nov 2017, 6:49 PM
Ynellaras
Ynellaras - avatar
6 Answers
+ 6
https://code.sololearn.com/cBYy3Wy0Lc9s/#rb max = gets.to_i for i in 1..max puts i end
16th Nov 2017, 7:05 PM
AgentSmith
+ 3
@Ynellaras Check out what Immortal posted. That'll give you the end result only. However, in this particular example, the end result is always going to be equal to max since that's our end range and we're only printing out what i is after the loop (always equal to max). With that being said, if you used that loop to do calculations or anything else that's actually useful, what Immortal posted will give you the desired result of it. And yes, because of you, I've learned more about Ruby today that I ever have prior. lol So thank you for making me a better person today. As my Grandma use to say, if you don't have the resources, be resourceful. I started learning the language to help you out, and since I didn't know the language prior, I just pulled it up and started reading it. @Immortal Thanks for the kind words. It always makes me happy to see other people take interest in programming and having a desire to learn, so I do what I can to help that process.
16th Nov 2017, 7:30 PM
AgentSmith
+ 2
I'm so motivated to learn new things. I also started a Ruby course on "edX" in case of I missed something important. Also I'm using summary method of studying recalling what I learned previously. Just can't stop gaining knowledge with this infinite supply and people like you.
16th Nov 2017, 7:13 PM
Ynellaras
Ynellaras - avatar
+ 2
@Immortal wow, that's really you. I remember your tests and I watched your page in searches of information. Big thanks!!!
16th Nov 2017, 7:16 PM
Ynellaras
Ynellaras - avatar
+ 2
Oops, didn't realize you placed that in your post! :D I suppose too much information is better than not enough. lol
16th Nov 2017, 7:35 PM
AgentSmith
+ 1
That's great but how to put just the final result of this? Not the values of whole cycle. You said you wasn't familiar with Ruby at all but I'm amazed with your skill of finding the information. Keep it up.
16th Nov 2017, 7:10 PM
Ynellaras
Ynellaras - avatar