Search
 
SCRIPT & CODE EXAMPLE
 

PERL

perl loops

# The main loops in Perl are for, foreach, and while, though there are also
# do..while and until loops. Here's the syntax for each, with examples:
# Basic syntax of for loop:
for ( init; condition; increment ) {
    code to run;
}
# Example usage of for loop:
for (my $i = 5; $i < 10; $i += 1) {  
    print "Value of i: $i
";
}

# Basic syntax of foreach loop:
foreach var (list) {
	code to run;
}
# Example usage of foreach loop:
@list = (2, 20, 30, 40, 50);
foreach $i (@list) {
    print "Value of i: $i
";
}

# Basic syntax of while loop:
while( condition ) {
   code to run;
}
# Example usage of while loop:
my $i = 5;
while( $i < 10 ) {
   print "Value of i: $i
";
   $i += 1;
}

# Basic syntax of do..while loop:
# Similar to while loop but always executes at least once
do {
   code to run;
} while( condition );
# Example usage of do..while loop:
$i = 5;
do {
   print "Value of i: $i
";
   $i += 1;
} while( $i < 10 );

# Basic syntax of until loop:
# Sort of the opposite of a while loop, it loops over the code until the
# condition becomes true
until( condition ) {
   code to run;
}
# Example usage of until loop:
$i = 5;
until( $i > 10 ) {
   print "Value of i: $i
";
   $i += 1;
}
Comment

perl for loop

# Basic syntax:
for ( init; condition; increment ) {
    code to run;
}

# Example usage:
for (my $i = 5; $i < 10; $i += 1) {  
    print "Value of i: $i
";
}
Comment

perl for loop


        
            
        
     #!/usr/bin/perl
use warnings;
use strict;

my @c = (1..6);
for(my $i = 0; $i <= $#c; $i++){
	print("$c[$i] 
");
}
Comment

PREVIOUS NEXT
Code Example
Perl :: perl regex 
Perl :: perl while loop 
Perl :: perl sprintf YYYYMMDD sample 
Perl :: perl make a new directory 
Perl :: fonction perl 
Perl :: perl rename a file 
Pascal :: pascal read 
Pascal :: delay() in Pascal 
Pascal :: print pascal triangle 
Powershell :: takeown command 
Powershell :: powershell show which diorecty is temp 
Gdscript :: gdscript vector2 
Clojure :: call function in clojure 
Cobol :: gatsby with yarn 
Assembly :: ror loading webview: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state.. 
Assembly :: where correlation is used 
Assembly :: nano error reading lock file not enough data read 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: list all node processes 
Javascript :: javascript radian to degree 
Javascript :: check react version terminal windows 
Javascript :: jquery only number allowed to 10 digit 
Javascript :: count number of checkboxes in html jquery 
Javascript :: javascript lowercase string 
Javascript :: regex date validation mm/dd/yyyy 
Javascript :: how to console.log formData 
Javascript :: js scroll to id 
Javascript :: sleep for 1 second 
Javascript :: jquery css add important 
Javascript :: dconf-editor install terminal 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =