CLS PRINT " +------------------------------------------+ " PRINT " | | " PRINT " | LOOP TIMER | " PRINT " | | " PRINT " | Measures the speed of several | " PRINT " | different loop structures. | " PRINT " | | " PRINT " +------------------------------------------+ "' done := FALSE // Setting this to TRUE signals the end of the program. REPEAT PRINT'"1: Time FOR/NEXT loop" PRINT "2: Time REPEAT/UNTIL loop" PRINT "3: Time WHILE/ENDWHILE loop" PRINT "4: Time recursive PROC loop" PRINT "5: Quit"' INPUT "Please enter your choice: " : choice WHILE choice < 1 OR choice > 5 DO INPUT "Please choose a number from the menu: " : choice ENDWHILE IF choice = 5 THEN // The user chose 'Quit'. done := TRUE ELSE INPUT "How many iterations? " : max% WHILE max% < 1 DO INPUT "Please enter a positive number: " : max% ENDWHILE PRINT max%; " iterations coming up..." CASE choice OF WHEN 1 t := time_for_next_loop (max%) WHEN 2 t := time_repeat_until_loop (max%) WHEN 3 t := time_while_endwhile_loop (max%) WHEN 4 t := time_proc_loop (max%) OTHERWISE PRINT "Oops, something's gone wrong :(" PRINT "We shouldn't be here..." done := TRUE ENDCASE PRINT "That took "; t / 60; " seconds."'// time is measured in 60ths/sec ENDIF UNTIL done PRINT'"Goodbye." // еееееееееее Procedures еееееееееееееееее // ------------------------------------------------ FOR/NEXT loop FUNC time_for_next_loop (n%) t% := TIME FOR x% := 1 TO n% DO // The timed loop NEXT x% RETURN TIME - t% ENDFUNC time_for_next_loop // ------------------------------------------------ REPEAT/UNTIL loop FUNC time_repeat_until_loop (n%) t% := TIME x% := 1 REPEAT x% := x% + 1 UNTIL x% = n% RETURN TIME - t% ENDFUNC time_repeat_until_loop // ------------------------------------------------ WHILE/ENDWHILE loop FUNC time_while_endwhile_loop (n%) t% := TIME x% := 1 WHILE x% < n% DO x% := x% + 1 ENDWHILE RETURN TIME - t% ENDFUNC time_while_endwhile_loop // ------------------------------------------------ PROC loop FUNC time_proc_loop (n%) PRINT "WARNING: this loop uses a lot of memory. Be careful!" IF ask_yes_no% ("Okay to proceed? ") THEN t% := TIME do_proc_loop (n%) RETURN TIME - t% ELSE RETURN 0 ENDIF ENDFUNC time_proc_loop PROC do_proc_loop (n%) IF n% > 1 THEN do_proc_loop (n% - 1) ENDIF ENDPROC do_proc_loop // ------------------------------------------------ Ask yes/no question FUNC ask_yes_no% (prompt$) CLOSED done := FALSE WHILE NOT done DO INPUT prompt$ : yn$ IF yn$ = "y" OR yn$ = "n" THEN done := TRUE ELSE PRINT "Please answer 'Y' or 'N'" ENDIF ENDWHILE RETURN yn$ = "y" ENDFUNC ask_yes_no%