ruby 嵌套函数

嵌套直到循环 (Nested until loop)

Alike for, while, and do...while, until loop can also be nested for meeting the specific purpose. In this type of nesting, two until loops work in the combination such that at first, the outer loop is triggered which results in the execution of the inner loop. The outer Until loop is not invoked as long as the inner loop does not comes out to be true. It is a kind of Entry control loop which simply means that first the outer Boolean expression is processed; if it is false then the pointer will move to the inner loop to check inner condition. The whole execution will take place in the same manner.

与for, while和do ... while一样 , 直到循环也可以嵌套以满足特定目的。 在这种嵌套中,两个直到循环在组合中起作用,这样一来,首先触发外循环,从而执行内循环。 只要内部循环不成立,就不会调用外部的直到循环。 这是一种Entry控制循环,仅表示首先处理外部布尔表达式;然后进行处理。 如果为假,则指针将移至内部循环以检查内部条件。 整个执行将以相同的方式进行。

Syntax:

句法:

    until conditional [do]
until conditional [do]
# code to be executed
end
# code to be executed
end

Example 1:

范例1:

=begin
Ruby program to find the sum of numbers lying
between two limits using nested until loop
=end
puts "Enter the Upper limit"
ul=gets.chomp.to_i
puts "Enter the Lower limit"
ll=gets.chomp.to_i
until ul==ll
num=ul
temp=ul
sum = 0
until num==0
#implementation of until loop
rem=num%10
num=num/10
sum=sum+rem
end
puts "The sum of #{temp} is #{sum}"
ul=ul-1
end

Output

输出量

Enter the Upper limit
1000
Enter the Lower limit
980
The sum of 1000 is 1
The sum of 999 is 27
The sum of 998 is 26
The sum of 997 is 25
The sum of 996 is 24
The sum of 995 is 23
The sum of 994 is 22
The sum of 993 is 21
The sum of 992 is 20
The sum of 991 is 19
The sum of 990 is 18
The sum of 989 is 26
The sum of 988 is 25
The sum of 987 is 24
The sum of 986 is 23
The sum of 985 is 22
The sum of 984 is 21
The sum of 983 is 20
The sum of 982 is 19
The sum of 981 is 18

Example 2:

范例2:

Pattern printing: Print the following pattern

图案打印:打印以下图案

    0
01
012
0123
01234

Code:

码:

=begin
Ruby program to print the given pattern.
=end
num=0
until (num==6)
j=0
until(j==num)
print j
j+=1
end
puts ""
num+=1
end

翻译自: https://www.includehelp.com/ruby/nested-until-loop-with-examples.aspx

ruby 嵌套函数

ruby 嵌套函数_Ruby嵌套直到循环带有示例相关推荐

  1. ruby 嵌套函数_Ruby嵌套有示例的循环

    ruby 嵌套函数 嵌套循环 (Nested for loop) Nesting of for loop means one for loop is available inside another ...

  2. matlab if嵌套函数,MATLAB嵌套函数的应用

    嵌套函数在求解积分上限中的应用 例1如下述积分表达式,已知a.e和l,如何求得β0? 本例关于β的积分结果不能解析表达,需要数值积分来做,同时还要求一个非线性方程.代码如下: function sol ...

  3. ruby 执行函数_Ruby at()函数

    ruby 执行函数 Ruby中的at()函数 (at() function in Ruby) If you are working with arrays in Ruby, sometimes you ...

  4. vue 函数嵌套函数再嵌套函数 _this的巨大作用

    openOCR3(){var _this= this;uni.chooseImage({count: 1, //默认9sizeType: ['original', 'compressed'], //可 ...

  5. c语言atoll函数怎么用_C ++中带有示例的atoll()函数

    c语言atoll函数怎么用 C ++ Atoll()函数 (C++ atoll() function) atoll() function is a library function of cstdli ...

  6. Python基础第六天——函数的使用、函数的参数、函数的返回值、函数的嵌套、命名空间、作用域、函数对象...

    一.拾遗 1.通常情况下无参函数只是进行操作,所以不需要返回值:有参数函数则需要返回值. 2.练习: 判断用户输入一串字符,如果这串字符的长度小于5则重新输入,如果大于5则退出循环. while Tr ...

  7. Python基础教程:嵌套函数、闭包

    嵌套函数 在函数中定义另一个函数称为嵌套函数. 嵌套函数可以访问包围范围内的变量. def print_msg(msg):def printer():print(msg)printer()print_ ...

  8. python 避免多重条件嵌套_如何避免多层嵌套函数

    我使用的python代码有4个层次的嵌套函数.您可以看到以下示例:class TestClass: def __init__(self): pass def calculate(self, x, y) ...

  9. tr闭包_嵌套函数及闭包

    这篇文章其实是要讲闭包的一些初级应用,但是为了将闭包,我们还是从嵌套函数开始说吧,纵使所有的JavaScript函数都可以说是闭包,但是只有当一个嵌套函数被导出到它所定义的作用域之外时,这种闭包才是有 ...

最新文章

  1. Cell Reports:张瑞福团队揭示抗生素调控微生物肥料菌种根表定殖成膜的新机制...
  2. 《中国文化要略》第八章 古代教育 第九章 科举制度
  3. WGCNA | weighted correlation network analysis
  4. IXWebHosting主机如何退款中文图解教程
  5. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_04 IO字节流_12_练习_文件复制...
  6. 4207. 最长合法括号子序列
  7. 修复Git打包的一个Bug
  8. java 相关学习资料汇总下载(全)
  9. 三阶魔方还原 - 只需7步6个公式
  10. 无线网主dns服务器,无线网的dns怎么设置
  11. 图形编程技术笔记整理1.1-1.6
  12. 给最真的自己加上static final
  13. 数字逻辑电路(一、基本概述、数制及其转换)
  14. web手机端真机测试
  15. 聊聊Hive数据血缘——从Atlas没有列级血缘的Bug讲起
  16. YII2使用时出现The file or directory to be published does not exist
  17. 【原创】十六进制数值与字符串之间的转换(原封不动的转换)
  18. tomcat怎样配置多个域名
  19. 一键设置IP地址(快速设置ip地址)
  20. 企业电子招投标采购系统源码之功能模块

热门文章

  1. python中升级pip报错_linux系统下pip升级报错的解决方法
  2. uniapp uni.request GET方式请求,不能直接传数组解决方法
  3. flow 静态类型检查 js
  4. 一套比较完整的前端技术选型,需要规整哪些东西,你知道不?
  5. 前端程序员容易忽视的一些基础知识
  6. 关于设计模式的胡思乱想
  7. Java实现回形数,只利用数组、循环和if-else语句
  8. AlvinZH双掉坑里了
  9. 《Linux命令行与shell脚本编程大全 第3版》创建实用的脚本---10
  10. class threading.Thread()说明: