viernes, 10 de abril de 2020

While and until Loops in Perl online examples with simulation


While and until Loops in Perl

https://www.codesdope.com/perl-while-and-until/


I will start this chapter by asking you to take your friend's name as input. The solution is simple, you will use '<>' operator. If you have to ask the name of two friends, then you will use '<>' two times. Now, suppose you have to take the input of the name of 50 students.
No, no, no, using '<>' 50 times is not a good option. This kind of situation can be easily handled using a loop. You will learn while and until loop in this chapter.
A loop does the same work as its name. It repeats the codes inside its body to a fixed number of times ( not necessarily ). Let's see an example of while loop to print the multiplication table of 14 on the screen:
$i = 1;
while ($i<=10){
  print $i*14,"\n";
  $i++;
}
Output
So, the syntax of while loop is
while (condition){
  statement
  statement
  statement
  statement
  ....
}

No hay comentarios:

Publicar un comentario