The source code to demonstrate the nested "do" loop is given below. The given program is compiled and executed successfully.
#Ruby program to demonstrate the
# nested "do" loop.
cnt1=2;
cnt2=0;
loop do
cnt2=1;
loop do
print (cnt1*cnt2)," ";
cnt2=cnt2+1;
if cnt2>10
break;
end
end
cnt1=cnt1+1;
puts;
if (cnt1>5)
break;
end
end
In the above program, we created two variables cnt1, cnt2 that are initialized with 2, 0 respectively. Then we used a nested "do" loop to print tables from 2 to 5.
Program/Source Code:
The source code to demonstrate the nested "do" loop is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two variables cnt1, cnt2 that are initialized with 2, 0 respectively. Then we used a nested "do" loop to print tables from 2 to 5.
need an explanation for this answer? contact us directly to get an explanation for this answer