Previous topic | Ada Home Page | Index

Safe I/O

    type days is (mon, tue, wed, thu, fri, sat, sun);

    function get_day return days is

        local_day  : days;                -- entered by user
        good_day   : boolean := FALSE:    -- loop control

    begin 

        while not good_day loop

            begin -- while block

                PUT ("Enter a day name (first 3 letters) : ");
                GET (local_day);

                -- this point only reached if valid entry given
                good_day := TRUE;

            exception -- exception handler for while block

                when DATA_ERROR =>
                    PUT ("Must be first 3 letters of a day name");
                    NEW_LINE;
                    SKIP_LINE;

            end; -- while block

        end loop;

        SKIP_LINE;
        return local_day;

    end get_day;


Previous topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 26 Feb 96