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

for ($i=0; $i<#whatever#; $i++){
	#your code
}
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 variables 
Perl :: perl mongodb conf location 
Perl :: mean data frame columns by group R 
Perl :: perl format decimal 2 places not rounding 
Perl :: Perl (perl 2018.12) sample 
Pascal :: pascal halt program until any button is pressed 
Pascal :: pascal sleep 
Pascal :: pascal 
Powershell :: debloat window 10 
Powershell :: Windows 10 fbomber Batch Script 
Gdscript :: godot make string all uppercase 
Clojure :: clojure def 
Lisp :: print lisp 
Assembly :: assembly fibonacci 
Assembly :: how to check if chat is nsfw discord.py 
Assembly :: re optional 
Assembly :: fatal error: opencv2/core/version.hpp: No such file or directory 
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
9+8 =