Skip to content

Instantly share code, notes, and snippets.

@rozer007
Created December 6, 2021 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rozer007/6f4095e4b3b0b9dc1557bf930b1cd088 to your computer and use it in GitHub Desktop.
Save rozer007/6f4095e4b3b0b9dc1557bf930b1cd088 to your computer and use it in GitHub Desktop.
Loops in Perl
Q1. what is last statement in Perl?
ans: last statement is use to break out of a running loop.
Q2.How can we skip to the next iteration in a loop?
ans we can use next statement to skip to the next iteration of a loop.
Q3.How many type of loop are there in perl?
ans: There are three types :- for loop, while loop and do while loop.
Q4.What is the syntax for for loop?
ans : for(initialize;condition;updation){}
Q1. What will be the output of the statement?
for(my$i=0;;$i++)
{
print"hello";
}
a) hello
b) hellohellohello......infinite
c) none of the above
d) error
ans: b)
Q2. What will be the output?
my $i=0;
while($i<3)
{
unless($i==2)
{print "hello";}
print "pep";
$i++;
}
a)pepepehellopep
b)hellopephellopeppep
c)hellopephellopephellopep
d)none of the above
ans: b)
Q3. my $i=0;
do{
print"hello";
$i=5;
}while($i>0 and $i<5);
How many time will "hello" be printed :
a) 1
b) 2
c) infinite
d) none of the above
Q4.What will be the output:
my $i=0;
while($i<5){
if($i==4)
{
print $i++;
next;
}
$i++;
}
a) 4
b) 5
c) 3
d) none of the above
ans: a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment