c# javascript_在Java,Javascript,C ++,C#,Python编程语言中进行While循环

c# javascript

c# javascript

Programming languages like Javascript, C++, C#, Python provides while loops in order to iterate over the given list, array, set etc. while loop is a very important part of the programming language because of its functionality. In this tutorial, we will examine and compare a while loop for programming languages like Javascript, C++, C#, and Python.

诸如Javascript,C ++,C#,Python之类的编程语言提供了while loops以遍历给定的列表,数组,集合等while loop由于其功能而成为编程语言中非常重要的一部分。 在本教程中,我们将检查和比较Java语言,C ++,C#和Python等编程语言的while循环。

JavaScript while循环 (Javascript while loop)

Javascript provides different syntax of while loops. The general syntax is like below.

Javascript提供了while循环的不同语法。 通用语法如下。

唯一条件 (Only Condition)

We just need to provide condition after the while keyword.

我们只需要在while关键字之后提供条件。

while (CONDITION) {
    CODE
}

In this example, we will increase the i variable and check whether it is lower than 5.

在此示例中,我们将增加i变量并检查其是否小于5。

while (i < 5){

    text += "Value is " + i;
    i++;
}

While Block之后的条件 (Condition After While Block)

We can also define condition checks after the while block. This will ensure that the whole block will be executed at least one time and checked after execution.

我们还可以在while块之后定义条件检查。 这将确保整个块至少执行一次并在执行后检查。

do {
    CODE
}
while (CONDITION);

In this example we will first increase the i variable and then check whether its lower than 5

在此示例中,我们将首先增加i变量,然后检查其是否小于5

do{
    text += "Value is " + i;
    i++;
}while (i < 5);

C和C ++ while循环 (C and C++ while loop)

C and C++ programming languages are using very similar syntax. Their while loop is very similar to the Javascript because Javascript derived some syntax from these languages.

C和C ++编程语言使用的语法非常相似。 它们的while循环与Javascript非常相似,因为Javascript从这些语言派生了一些语法。

唯一条件 (Only Condition)

We just need to provide condition after the while keyword.

我们只需要在while关键字之后提供条件。

while (CONDITION) {
    CODE
}

In this example, we will increase the i variable and check whether it is lower than 5.

在此示例中,我们将增加i变量并检查其是否小于5。

while (i < 5){
    printf("Value is %d", i);
    i++;
}

While Block之后的条件 (Condition After While Block)

We can also define condition check after the while block. This will ensure that the while block will be executed at least one time and checked after execution.

我们还可以在while块之后定义条件检查。 这将确保while块将至少执行一次并在执行后检查。

do {
    CODE
}
while (CONDITION);

In this example we will first increase the i variable and then check whether its lower than 5

在此示例中,我们将首先增加i变量,然后检查其是否小于5

do{
    printf("Value is %d", i);
    i++;
}while (i < 5);

C#while循环 (C# while loop)

C# programming language uses very similar concepts of the C and C++ programming languages. We can use the following code in order to loop with a while. In this example, we will write i variable value to the console and check whether it is lower than 5.

C#编程语言使用与C和C ++编程语言非常相似的概念。 我们可以使用以下代码来循环一段时间。 在此示例中,我们将i变量值写入控制台,并检查其是否小于5。

using System;

class Program
{
    static void Main()
    {

        int i = 0;
        while (i < 5)
        {
            Console.WriteLine(i);

            i++;
        }
    }
}

做一会儿 (Do While)

We can also implement the same logic with do while operations.

我们还可以使用do while操作实现相同的逻辑。

using System;

class Program
{
    static void Main()
    {
        int i = 0;

        do
        {
            Console.WriteLine(i);

            i++;
        } while (i<= 5);
    }
}

Python while循环 (Python while loop)

Python is a bit different language from other counterparts like Javascript, C, C++, and C#. Python uses indents as block specifiers so we will start while block with 3 spaces. In this example, we will check the variable i if it is lower than 5 and then print it.

Python与Javascript,C,C ++和C#等其他语言有点不同。 Python使用缩进作为块说明符,因此我们将从3个空格开始。 在此示例中,我们将检查变量i是否小于5,然后进行打印。

i = 1
while i < 5:
   print(i)
   i += 1
LEARN MORE  C For Loop and Iteration
了解更多C用于循环和迭代

翻译自: https://www.poftut.com/while-loop-in-java-javascript-cpp-csharp-python-programming-languages/

c# javascript

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值