Forum: Ruby What's wrong?

0054c6f7f4e743bbe52cb7576ec34408?d=identicon&s=25 Komil Mum (komil_m)
on 2014-04-01 15:14
Why this program doesn't work?
Only the internal cycle works ((

i = 10
cn = 0
while cn < 3
  while i < 12
    puts i, cn
    i += 1
  end
  cn += 1
end

Thanks!
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-04-01 19:06
Hi Komil Mum,

Your outer loop also works three times,but it's not printing anything
because your i has reached 12 already, Please execute the below program,
you will get to understand,

i = 10
cn = 0
while cn < 3
  while i < 12
    puts i, cn
    i += 1
  end
  puts i
  cn += 1
end
0054c6f7f4e743bbe52cb7576ec34408?d=identicon&s=25 Komil Mum (komil_m)
on 2014-04-01 19:53
Hi, Raja gopalan,

Thanks, I realized my mistake and corrected it))
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-04-01 19:54
welcome
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.