loops.pl सम्पादन

#!/usr/bin/perl

# This program displays a temperature conversion table showing Fahrenheit
# temperatures from 0 to 100, in increments of 10, and the corresponding
# Celsius temperatures using While, For, and Do loops.

sub while_loop
{
    my $f;
    my $c;
    
    $f = 0;
    print "F°    C°", "\n";
    while ($f <= 100) 
    {
        $c = ($f - 32) * 5 / 9;
        print $f . " = " . $c, "\n";
        $f += 10;
    }
}

sub for_loop
{
    my $f;
    my $c;
    
    print "F°    C°", "\n";
    for ($f = 0 ; $f <= 100 ; $f += 10) 
    {
        $c = ($f - 32) * 5 / 9;
        print $f . " = " . $c, "\n";
    }
}

sub do_loop
{
    my $f;
    my $c;
    
    print "F°    C°", "\n";
    $f = 0;
    do 
    {
        $c = ($f - 32) * 5 / 9;
        print $f . " = " . $c, "\n";
        $f += 10;
    } while $f <= 100;
}

sub main
{
    while_loop();
    for_loop();
    do_loop();
}

main();

कोशिश करो सम्पादन

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।

यह भी देखें सम्पादन