How to change step value inside the loop?

shade88

I want to increase my step value in each loop iteration, but my solution is not working.

n=1
(0..100).step(n) do |x|
 puts x
 n+=1 
end

Is there any way to change "n" or I'm must using "while loop" or smth else?

Benjamin Udink ten Cate

I assuming you are trying to print 1, 3, 6, 10, 15, 21 etc.

step documentation says:

Iterates over range, passing each nth element to the block. If the range contains numbers, n is added for each iteration.

So what you are trying to do can't be done with step. A while or traditional for loop should do the trick.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Change step value inside range function?

From Dev

Value inside loop doesn't change

From Dev

How to change value inside function

From Dev

How to return a value inside of while loop

From Dev

How to get textbox value that are inside of while loop?

From Dev

how to return value inside of forEach loop in JavaScript

From Dev

(Oracle) How to get sum value inside loop?

From Java

Why does the value of typeof null change inside a loop?

From Dev

Java - can't change int value inside for-each loop

From Dev

How to prevent value change inside $watch

From Dev

How to change the value of sum function inside the query?

From Dev

How to change value of property inside data attribute

From Dev

jquery .change inside loop

From Dev

change index inside a for loop

From Dev

Change loop inside a loop with Matlab

From Dev

use a do loop inside an infile data step

From Dev

How to change value if error occurs in for loop?

From Dev

How to change object value in a loop in Dart

From Dev

C# how to change textbox value by loop?

From Dev

how to take change value in loop scala

From Dev

Android how to change value of a Key/Value Pair inside JSONObject

From Dev

Python - Why backup variable inside loop is being updated if I don't change it value inside?

From Dev

How to change points individually in plot with for loop having if() inside? R

From Dev

How to change or customize JBehave step?

From Dev

for loop in Bash doubling the step value each time

From Dev

Change Column Dynamically inside a Loop

From Dev

How to get value from multiple input fields which are inside a for loop

From Dev

Makefile: How to use a loop value inside a shell block

From Dev

How do I return the user input value inside of a while loop?

Related Related

  1. 1

    Change step value inside range function?

  2. 2

    Value inside loop doesn't change

  3. 3

    How to change value inside function

  4. 4

    How to return a value inside of while loop

  5. 5

    How to get textbox value that are inside of while loop?

  6. 6

    how to return value inside of forEach loop in JavaScript

  7. 7

    (Oracle) How to get sum value inside loop?

  8. 8

    Why does the value of typeof null change inside a loop?

  9. 9

    Java - can't change int value inside for-each loop

  10. 10

    How to prevent value change inside $watch

  11. 11

    How to change the value of sum function inside the query?

  12. 12

    How to change value of property inside data attribute

  13. 13

    jquery .change inside loop

  14. 14

    change index inside a for loop

  15. 15

    Change loop inside a loop with Matlab

  16. 16

    use a do loop inside an infile data step

  17. 17

    How to change value if error occurs in for loop?

  18. 18

    How to change object value in a loop in Dart

  19. 19

    C# how to change textbox value by loop?

  20. 20

    how to take change value in loop scala

  21. 21

    Android how to change value of a Key/Value Pair inside JSONObject

  22. 22

    Python - Why backup variable inside loop is being updated if I don't change it value inside?

  23. 23

    How to change points individually in plot with for loop having if() inside? R

  24. 24

    How to change or customize JBehave step?

  25. 25

    for loop in Bash doubling the step value each time

  26. 26

    Change Column Dynamically inside a Loop

  27. 27

    How to get value from multiple input fields which are inside a for loop

  28. 28

    Makefile: How to use a loop value inside a shell block

  29. 29

    How do I return the user input value inside of a while loop?

HotTag

Archive