Control Structures

The do {} while / until loop

The while / until statement we saw before tests its condition at the top of every loop, before the loop is entered.

The do {} while / until construct, on the other hand, allows us to test the condition at the bottom of the loop, after it is executed once.

Using while:

}while (expression);   #if condition is true, execute block again

Using until:

}until (expression);   #if condition is false, execute block again


Ask user to enter no. of translated nucleotides in an mRNA sequence, and calculate the number of amino acids in the resulting protein only if the nucleotide number is positive and is divisible by 3.


my ($nuc, $aa);


  print "Please enter no. of translated nucleotides: ";
  $nuc = <STDIN>;
  chomp ($nuc);

}until ($nuc > 0 and $nuc % 3 == 0);

print "No. of amino acids: $aa\n";

Other solutions to the same problem: click here.

Table of Contents.
Previous | Next.