What Is Loop For Programming Languages Like Java, C/C+, PHP, Python, C#, JavaScript, Bash?

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM

Loops are a very important part of the programming languages. Loops are used to iterate over given collection, array, list, etc. There are mainly two types of loops named for loop and while loop. There are other types of loops but they can specially design for the specific programming languages.

Loop Types

As stated previously there are two types of general loop. They are while and for loops. For loop is more popular than while loop. Loops need some start case, continue condition and end condition which will end the loop to prevent infinite loop.

For Loop

For loop will have the general syntax below.

  • START_STATEMENT is used for the first statement during execution and start of the for  loop. After the first execution, it will not use again. It is like an initializer.
  • EXECUTION_STATEMENT will be executed in every step of the loop. It will help to change the END_CONDITION variables to reach END_CONDITION.
  • END_CONDITION specifies the end condition for the loop. If the end condition met the loop will end.

While Loop

While loop will have the following general syntax below. As we can see while loop is more simple then for loop where it has END_CONDITION.

  • END_CONDITION is the condition used in While loop where it specifies the end condition by using variables. When the end condition met the while loop will end.

Java Loop

Java programming language provides both for and while loops. It is very similar to the C/C++ and C# programming languages.

Java For Loop

Java programming language for loop will have the following syntax. It is the same which is described at the beginning of the post.

and as an example, we will start counting from 1 to the 10 with the following Java for a loop.

  • int i is the start statement of the loop. It will create an integer variable named i and set its initialization value to the 1.
  • i < 11 is the end condition which will be checked in every loop step whether it meets or nor. If the end condition is met which means i is lower then 11 the loop will continue where when i is higher then 11 the loop will end.
  • i++ is the execution statement which is executed in every step of the loop. This is used to reach i to the end condition by increasing it.

Java While Loop

Java programming language also provides while loop like below.

We will use the following example which will start counting from 1 to the 10 .

  • int i = 1 is used to specify initialize i.
  • i < 11 is the end condition where the loop will end when i reaches to the 10.

C/C++ Loop

C/C++ is very similar languages to Java and C#.

C/C++ For Loop

C/C++ programming languages for loop will have the following syntax. It is the same which is described at the beginning of the post.

and as an example, we will start counting from 1 to the 10 with the following C/C++ for a loop.

  • int i is the start statement of the loop. It will create an integer variable named i and set its initialization value to the 1.
  • i < 11 is the end condition which will be checked in every loop step whether it meets or nor. If the end condition is met which means i is lower then 11 the loop will continue where when i is higher then 11 the loop will end.
  • i++ is the execution statement which is executed in every step of the loop. This is used to reach i to the end condition by increasing it.

C/C++ While Loop

C/C++ programming languages also provide while loop like below.

We will use the following example which will start counting from 1 to the 10 .

  • int i = 1 is used to specify initialize i.
  • i < 11 is the end condition where the loop will end when i reaches to the 10.

PHP Loop

PHP programming language provides both for and while loops. It is very similar to the C/C++ and C# programming languages.

PHP For Loop

PHP programming language for loop will have the following syntax. It is the same which is described at the beginning of the post.

and as an example, we will start counting from 1 to the 10 with the following PHP for a loop.

LEARN MORE  How To Linux Bash For Loop In Files?

  • int i is the start statement of the loop. It will create an integer variable named i and set its initialization value to the 1.
  • i < 11 is the end condition which will be checked in every loop step whether it meets or nor. If the end condition is met which means i is lower then 11 the loop will continue where when i is higher then 11 the loop will end.
  • i++ is the execution statement which is executed in every step of the loop. This is used to reach i to the end condition by increasing it.

PHP While Loop

PHP programming language also provides while loop like below.

We will use the following example which will start counting from 1 to the 10 .

  • int i = 1 is used to specify initialize i.
  • i < 11 is the end condition where the loop will end when i reaches to the 10.

Python Loop

Python is a programming language which is designed for novice users. Python provides a different syntax from other programming languages like C/C++, Java, C# .

Python For Loop

We can use for loop by specifying a list or using range() function which will create an iterable list for specified range with numbers.

We will loop over a list from 1 to 10  which is created with the range() function like below.

Python For Loop

Python For Loop

Python While Loop

While loop will be similar to the for loop where we will create x variable with the 1 initialization value and then increment in the while loop one by one.

While Loop

While Loop

C# Loop

The C# programming language is very similar to the C/C++ and Java programming languages.

C# For Loop

C# programming languages for loop will have the following syntax. It is the same which is described at the beginning of the post.

and as an example, we will start counting from 1 to the 10 with the following  C# for a loop.

  • int i is the start statement of the loop. It will create an integer variable named i and set its initialization value to the 1.
  • i < 11 is the end condition which will be checked in every loop step whether it meets or nor. If the end condition is met which means i is lower then 11 the loop will continue where when i is higher then 11 the loop will end.
  • i++ is the execution statement which is executed in every step of the loop. This is used to reach i to the end condition by increasing it.
LEARN MORE  How To Linux Bash For Loop In Files?

C# While Loop

The C# programming language also provides while loop like below.

We will use the following example which will start counting from 1 to the 10 .

  • int i = 1 is used to specify initialize i.
  • i < 11 is the end condition where the loop will end when i reaches to the 10.

JavaScript Loop

The JavaScript programming language is very similar to the C/C++ and Java programming languages.

JavaScript For Loop

JavaScript programming languages for loop will have the following syntax. It is the same which is described at the beginning of the post.

and as an example, we will start counting from 1 to the 10 with the following JavaScript for a loop.

  • int i is the start statement of the loop. It will create an integer variable named i and set its initialization value to the 1.
  • i < 11 is the end condition which will be checked in every loop step whether it meets or nor. If the end condition is met which means i is lower then 11 the loop will continue where when i is higher then 11 the loop will end.
  • i++ is the execution statement which is executed in every step of the loop. This is used to reach i to the end condition by increasing it.

JavaScript While Loop

The JavaScript programming language also provides while loop like below.

We will use the following example which will start counting from 1 to the 10 .

  • int i = 1 is used to specify initialize i.
  • i < 11 is the end condition where the loop will end when i reaches to the 10.

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)