Scala中的do ... while循环

做...在Scala循环 (do...while loop in Scala)

do...while loop in Scala is used to run a block of code multiple numbers of time. The number of executions is defined by an exit condition. If this condition is TRUE the code will run otherwise it runs the first time only

Scala中的do ... while循环用于多次运行代码块。 执行次数由退出条件定义。 如果此条件为TRUE,则代码将运行,否则它将仅在第一次运行

The do...while loop is used when the program does not have information about the exact number of executions taking place. The number of executions is defined by an exit condition that can be any variable or expression, the value evaluated in TRUE if it's positive and FALSE if it's zero.

当程序没有有关发生的确切执行次数的信息时,使用do ... while循环 。 执行次数由退出条件定义,退出条件可以是任何变量或表达式,如果值为正数则为TRUE,如果为零则为FALSE

This loop always runs once in the life span of code. If the condition is initially FALSE. The loop will run once in this case.

该循环在代码的生命周期中始终运行一次。 如果条件最初为FALSE 。 在这种情况下,循环将运行一次。

The do...while loop is also called exit controlled loop because its condition is checked after the execution of the loop's code block.

do ... while循环也称为退出控制循环,因为在执行循环的代码块后会检查其条件。

Syntax of do...while loop:

do ... while循环的语法:

    do{
//Code to be executed...
} 
while(condition);

Flow chart of do...while loop:

do ... while循环流程图:

do while loop in Scala

Example of do...while loop:

do ... while循环的示例:

object MyClass {
def main(args: Array[String]) {
var myVar = 12; 
println("This code prints myVar even if it is greater that 10")
do{
println(myVar)
myVar += 2;
}
while(myVar <= 10)
}
}

Output

输出量

This code prints myVar even if it is greater that 10
12

Code explanation:

代码说明:

This code implements the use of the do...while loop in Scala. The do...while loop being an exit control loop checks the condition after the first run. This is why the code prints 12 but the condition is myVar should not be greater than 10. In this we put the condition after the code block this means the code will run like this, print myVar increment it by 2 (using assignment operator) and then checks for the condition of the loop.

这段代码实现了Scala中do ... while循环的使用。 作为退出控制循环的do ... while循环在第一次运行后检查条件。 这就是为什么代码打印12但条件为myVar不应大于10的原因。在此,我们将条件放在代码块之后,这意味着代码将像这样运行,打印myVar将其递增2(使用赋值运算符 ),然后检查循环条件。

The assignments for the do...while loop that you can complete and submit to know your progress.

您可以完成并提交do ... while循环的作业,以了解自己的进度。

Assignment 1 (difficulty - beginner): Print all prime numbers from 342 - 422 that is divisible by 3. (use do-while loop and functions.)

作业1(难度-初学者):打印342-422中所有可被3整除的质数。(使用do-while循环和函数。)

Assignment 2 (difficulty - intermediate): Print all number between 54 - 1145 that have 11,13 and 17 as a factor.

作业2(难度-中间):打印54-1145之间的所有数字,其中11、13和17为因数。

翻译自: https://www.includehelp.com/scala/the-do-while-loop-in-scala.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/377533.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

十七、完整神经网络模型训练步骤

以CIFAR-10数据集为例&#xff0c;训练自己搭建的神经网络模型架构 一、准备CIFAR-10数据集 CIFAR10官网使用文档 torchvision.datasets.CIFAR10(root"./CIFAR_10",trainTrue,downloadTrue) 参数描述root字符串&#xff0c;指明要下载到的位置&#xff0c;或已有数…

μC/OS-Ⅱ 操作系统内核知识

目录μC/OS-Ⅱ任务调度1.任务控制块2.任务管理3.任务状态μC/OS-Ⅱ时间管理μC/OS-Ⅱ内存管理内存控制块MCBμC/OS-Ⅱ任务通信1.事件2.事件控制块ECB3.信号量4.邮箱5.消息队列操作系统内核&#xff1a;在多任务系统中&#xff0c;提供任务调度与切换、中断服务 操作系统内核为每…

第二版tapout

先说说上次流回来的芯片的测试情况。 4月23日&#xff0c; 芯片采用裸片直接切片&#xff0c; bond在板子上&#xff0c;外面加了一个小塑料壳来保护&#xff0c;我们就直接拿回来测试了。 测试的主要分为模拟和数字两部分&#xff0c; 数字部分的模块基本都工作正常&#xff0…

cd-rom门锁定什么意思_CD-ROM的完整形式是什么?

cd-rom门锁定什么意思CD-ROM&#xff1a;光盘只读存储器 (CD-ROM: Compact Disc Read-Only Memory) CD-ROM is an abbreviation of "Compact Disc Read-Only Memory". It is a data storage memory in the form of an optical compact disc, which is read by a syst…

远程工作时的协作工具

远程工作时的协作工具 Google Hangout 用于日常会议和面对面交谈,在国内其实可以用qq来带起。Campfire 用于一天来的持续对话。Screenhero 用于分享屏幕&#xff0c;一起写代码,这个比较有用,可以一起写代码。Balsamiq 用于计划要制作的 UI。Asana 用于管理任务Google Docs 用于…

十八、完整神经网络模型验证步骤

网络训练好了&#xff0c;需要提供输入进行验证网络模型训练的效果 一、加载测试数据 创建python测试文件&#xff0c;beyond_test.py 保存在dataset文件夹下a文件夹里的1.jpg小狗图片 二、读取测试图片&#xff0c;重新设置模型所规定的大小(32,32)&#xff0c;并转为tens…

二分法变种小结(leetcode 34、leetcode33、leetcode 81、leetcode 153、leetcode 74)

目录二分法细节1、leetcode 34 在排序数组中查找元素的第一个和最后一个位置2、不完全有序下的二分查找(leetcode33. 搜索旋转排序数组)3、含重复元素的不完全有序下的二分查找(81. 搜索旋转排序数组 II)3、不完全有序下的找最小元素(153. 寻找旋转排序数组中的最小值)4、二维矩…

ID3D11DeviceContext::Dispatch与numthread笔记

假定——[numthreads(TX, TY, TZ)] // 线程组尺寸。既线程组内有多少个线程。Dispatch(GX, GY, GZ); // 线程组的数量。既有多少个线程组。 那么——SV_GroupThreadID{iTX, iTY, iTZ} // 【线程组内的】线程3D编号SV_GroupID{iGX, iGY, iGZ} // 线程组的3D编号SV_DispatchT…

kotlin 查找id_Kotlin程序查找Square区域

kotlin 查找idFormula to find area of Square: area side*side 查找Square面积的公式&#xff1a; area side * side Given the value of side, we have to find the area of Square. 给定side的值&#xff0c;我们必须找到Square的面积。 Example: 例&#xff1a; Input…

小米手环6解决天气未同步问题

最近我发现了我的米6手环天气不同步&#xff0c;打开Zepp Life刷新同步也不行&#xff0c;后来我找了一些网上的解决方法&#xff0c;尝试了一些也还不行&#xff0c;我这人喜欢瞎捣鼓&#xff0c;无意之间给整好了&#xff0c;后来我开始总结自己操作步骤&#xff0c;就在刚才…

c# datetime._C#| DateTime.Month属性与示例

c# datetime.DateTime.Month属性 (DateTime.Month Property) DateTime.Month Property is used to get the month component of this object. Its a GET property of DateTime class. DateTime.Month属性用于获取此对象的月份组成部分。 这是DateTime类的GET属性。 Syntax: 句…

C++ 内存分配层次以及memory primitives的基本用法

分配层次 C memory primitives 分配释放类型是否可重载mallocfree()C函数不可newdeleteC表达式不可::operator new()::operator delete()C函数可allocator::allocate()allocator::deallocate()C标准库可自由设计并以之搭配任何容器 分配与释放的四个用法 1、malloc and delet…

jQuery easyui layout布局自适应浏览器大小

首先解释一下标题的含义&#xff0c;当我们用jQuery easyui layout 进行布局的时候&#xff0c;可能会遇到这样一个问题&#xff0c;那就是当手工调整浏览器大小&#xff0c;或者最大化、还原窗口的时候&#xff0c;layout的某个区域不能填充因为浏览器扩大而产 生的空白区域&a…

JAVA 作业:图形界面

自己动手写的一个小JAVA 程序&#xff1a; 一个学生管理小系统&#xff0c;虽然很挫&#xff0c;但是这我学JAVA的第一步。学了2天JAVA没有白费&#xff01; 1 import java.awt.*;2 import java.awt.event.*;3 import java.util.ArrayList;4 5 import javax.swing.*;6 7 class …

一、Pytorch对自定义表达式自动求导

例如&#xff1a;y ax bx c&#xff0c;分别对a&#xff0c;b&#xff0c;c求导 若当a3&#xff0c;b4&#xff0c;c5&#xff0c;x1时 import torch from torch import autogradx torch.tensor(1.) a torch.tensor(3.,requires_gradTrue) b torch.tensor(4.,requires…

css菜单下拉菜单_在CSS中创建下拉菜单

css菜单下拉菜单CSS | 创建下拉菜单 (CSS | Creating Dropdown) Trivia: 琐事&#xff1a; We know the importance of navigation bar on our webpage, we know the importance of a list of items too on our webpage but what is the importance of dropdown in web pages?…

C++ 内存基本构件new/delete的意义、运用方式以及重载方式

目录一、对new的理解1、new做了什么2、new被编译器转为了什么3、operate_new源代码长啥样二、对delete的理解1、delete做了什么2、delete被编译器转为了什么3、operator delete源代码长啥样三、构造函数与析构函数的直接调用参考一、对new的理解 1、new做了什么 C告诉我们&am…

二、线性代数

一、张量 张量表示由一个数值组成的数组&#xff0c;这个数组可能有多个维度 import torchx torch.arange(15) x # tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])1&#xff0c;shape shape属性可以访问张量的形状 x.shape # torch.Size([15])2&a…

Wordpress prettyPhoto插件跨站脚本漏洞

漏洞名称&#xff1a;Wordpress prettyPhoto插件跨站脚本漏洞CNNVD编号&#xff1a;CNNVD-201311-413发布时间&#xff1a;2013-11-28更新时间&#xff1a;2013-11-28危害等级&#xff1a; 漏洞类型&#xff1a;跨站脚本威胁类型&#xff1a;远程CVE编号&#xff1a; 漏洞来源…

JavaScript学习笔记1

Netscape 公司 DOM模型&#xff0c;层(layer)-用ID标识。 HTML标记页面上的元素&#xff0c; <div id "mydiv">This is my div</div> CSS为这个页面元素定位 #mydiv{ position:absolute; left:320px; top:110px; } JavaScript 访问 (DOM模块不同&#x…