Perl for statement has the same grammar as C language for statement

Perl's for statement has the same grammar as C's for statement. Let's compare the Perl for statement with the C language for statement.

Perl for statement

Perl for statement.

# Perl for statement
for (my $i = 0; $i <100; $i ++) {
  
}

C language for statement

It is a C language for statement.

// C language for statement (C99 compatible)
for (int32_t i = 0; i <100; i ++) {
  
}

Comparison of Perl for statement and C language for statement

Let's compare the comparison between the Perl for statement and the C language for statement. The grammar is the same, such as how to use "()" and "{}", declare loop variables, and increment loop variables.

If you learn repetition with a C language for statement, you can use the grammar and concept as it is with Perl

If you learn repetition with a C language for statement, you can use the grammar and concept as it is in Perl. You can use the knowledge you learned in C language as it is in Perl.

Perl takes the syntax of the C for statement as it is. Also, in C language, like Perl, it is now possible to declare loop variables with a for statement in C99.

Perl is a programming language with dynamic types, but it is similar to the grammar of C for statements, except that it is dynamically typed.

Perl is designed so that users who have learned the Unix / Linux environment and C language can use the concepts learned there as they are, so the learning cost is low and programming can be done using the same concepts.

One of the nice features of Perl is that it aimed for affinity and cooperation from the beginning without overly criticizing the C language.

Other similarities between Perl and C

In this article, I wrote that Perl for statements are similar to C for statements, but Perl if statements, while statements, increments / decrements, operator types and priorities, scopes, and reference concepts. Is similar to C language.

Associated Information