While Loop In Java, Javascript, C++, C#, Python Programming Languages

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/while-loop-in-java-javascript-cpp-csharp-python-programming-languages/
PINTEREST
PINTEREST
INSTAGRAM

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

Javascript while loop

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

Only Condition

We just need to provide condition after the while keyword.

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

Condition After While Block

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

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

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.

LEARN MORE  How To Control Python For Loop with Break Statement?

Only Condition

We just need to provide condition after the while keyword.

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

Condition After While Block

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

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

C# while loop

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

Do While

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

LEARN MORE  Bash Infinite Loop Shell Linux

Python while loop

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

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/while-loop-in-java-javascript-cpp-csharp-python-programming-languages/
PINTEREST
PINTEREST
INSTAGRAM