Forum: Ruby Problem with nested while do

Ca3632c47ddf84ffbab3a62e506c412d?d=identicon&s=25 Martin Gawlikowski (mawgaw)
on 2015-12-02 23:56
Hallo,
I am new to Ruby and I can't solve this Problen.

I've got an Array w with 100 Elements called "w".
I want to divide the array with 1..100 divisors.

i = 0
j = 1.0

w.each do |i|

  while j <= 100.0 do

       print i/j,  ", "


       j +=1.0


 end

end

but it's not working.
Only the first Element of the Array is divided with
the hundred divisors.

I'd be very grateful for help.
Martin
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2015-12-07 21:44
you need to declare "j" inside the "each" loop. By declaring it at the
top, you're reaching j == 100, but you never set it back to 1.
7603ba3983248bd8b52ef8cfd5e041d7?d=identicon&s=25 Nivin Pauly (nivin17)
on 2015-12-28 09:00
You never reset the value of j to 0, and as such, your inner loop
condition is never true after the first run. Assigning j = 0; in the
outer loop afterward should fix it.
http://www.besanttechnologies.com/training-courses...
|
http://www.besanttechnologies.com/training-courses...
Ca3632c47ddf84ffbab3a62e506c412d?d=identicon&s=25 Martin Gawlikowski (mawgaw)
on 2016-01-01 21:34
thanks for the answers,

at the moment I haven't the time to follow it up, but I think my
question is solved

mawgaw
97fe58c7278a7d62096c67a5db947c06?d=identicon&s=25 Swati Sharma (swti6690)
on 2016-01-12 12:39
C programming allows to use one loop inside another loop.

http://www.hackingmind.com/hacking-tips-to-prevent...
4d09476900e718ca218f205c0a8f47d5?d=identicon&s=25 Giri Mani (girimani)
on 2016-03-24 11:34
Swati Sharma wrote in post #1180553:
> C programming allows to use one loop inside another loop.
>
> http://www.hackingmind.com/hacking-tips-to-prevent...

Very happy to see this blog. Gives a wonderful information with coded
explanaion. Thank you for this blog. very useful to me.
<a href= "http://www.thinkittraining.in/android">Android Training in
Chennai</a>
890bdebf31864e4c381827545a8c845a?d=identicon&s=25 Shree Sai (shreesai)
on 2016-08-18 13:08
very helpful blog to the learners like me thanks a lot...<a
href="http://www.credosystemz.com/training-in-chennai/be...
Selenium Training in Chennai</a> | <a
href="http://www.credosystemz.com/training-in-chennai/be...
Jobs</a>
68cb0e30bd5c99f3c1f95dc5238dc403?d=identicon&s=25 Priya Rajendran (rajapriyainchenni1)
on 2016-09-02 08:05
really nice and helpful aricle to me

<a
href="www.credosystemz.com/training-in-chennai/best-software-testing-training-in-chennai/best-selenium-training-in-chennai/">selenium
training in chennai</a> | <a href="
www.credosystemz.com/training-in-chennai/best-software-testing-training-in-chennai/best-selenium-training-in-chennai/">selenium
training institute in chennai</a> | <a
href="www.credosystemz.com/training-in-chennai/best-android-training-in-chennai/">Android
training in chennai</a> | <a
href="www.credosystemz.com/training-in-chennai/best-android-training-in-chennai/">android
training</a>
68cb0e30bd5c99f3c1f95dc5238dc403?d=identicon&s=25 Priya Rajendran (rajapriyainchenni1)
on 2016-09-02 08:05
nice and great blog

<a
href="www.credosystemz.com/training-in-chennai/best-software-testing-training-in-chennai/best-selenium-training-in-chennai/">selenium
training in chennai</a> | <a href="
www.credosystemz.com/training-in-chennai/best-software-testing-training-in-chennai/best-selenium-training-in-chennai/">selenium
training institute in chennai</a> | <a
href="www.credosystemz.com/training-in-chennai/best-android-training-in-chennai/">Android
training in chennai</a> | <a
href="www.credosystemz.com/training-in-chennai/best-android-training-in-chennai/">android
training</a>
Ae1077607ef4a89471cfde959edbb382?d=identicon&s=25 MarkC Phillips (markcphillips)
on 2016-12-07 05:18
Wow. cool post. I’d like to write like this too – taking time and real
hard work to make a great article… but I put things off too much and
never seem to get started. Thanks though. http://supersmashflash-2.com
http://bloonstowerdefense5game.com
8c7102b3895cd33546edbc62063e976c?d=identicon&s=25 Hong91 Hong91 (hong91)
on 2017-02-09 04:01
I want you to thank for your time of this wonderful read!!! I definately
enjoy every little bit of it and I have you bookmarked to check out new
stuff of your blog a must read blog!
http://wordcookiesgame.com/
http://hillclimbracing-2.com/
http://fivenightsatfreddys-4.com/
72cfe8802c07508bb88e47f3860656bd?d=identicon&s=25 Mathu Mitha (mathumitha)
on 2017-02-17 14:43
Hey,

you can solve the issues by contact our software trainers. Make sure,
They will easily all your programming problems.
http://www.globaltrainingbangalore.com
2d563f3cfcdef664ca1e9245034802ac?d=identicon&s=25 Suresh Kumar (sureshkuppam)
on 2017-03-02 12:38
Attachment: TOP_6_Fr__1_.jpg (300 KB)
FITA is the best training institute for Android Training in Chennai.
Android Course in Chennai offers the well trained MNC professionals as
trainers. Android Training institute in Chennai offers the placements in
top IT Companies. We have trained more than 10,000+ students from 125+
IT Courses. We are providing the unique teaching methodology. Enroll for
the demo class.
Call Us:@9841746595
http://www.fitaacademy.com/courses/android-trainin...
De8e7d28e9163a17401e2d62a9d94e37?d=identicon&s=25 Saravanan Raj (linuxsys)
on 2017-03-31 20:00
Hey,

you can solve the issues by contact our software trainers. Make sure,
They will easily all your programming problems.

http://sysacad.in/ |
http://sysadmintechnology.com/portfolio-view/red-h...
183cd0baa8d8cb1343627167b3b91e39?d=identicon&s=25 Jai Technomind (jai_technomind)
on 2017-04-01 05:58
5811ad02462d21b27dc49d291e70d7a6?d=identicon&s=25 Vignes Vignesjoseph (vignesjoseph)
on 2017-04-07 09:09
The reason your inner loop only executes once is because you initialize
j to 0 outside the loop and then never reset it again. After it runs the
first time the value of j is 10. It will never be less than 10 again.

A better way to do this is to use a for loop:

for (int i = 0; i < 10; i++){
    printf("i:%i\n", i);
    for (int j = 0; j < 10; j++){
        printf("j:%i\n", j);
    }
}
It also makes the code look cleaner.

https://www.gangboard.com/software-testing-trainin...
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.