How to resolve the algorithm Menu step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Menu step by step in the zkl programming language

Table of Contents

Problem Statement

Given a prompt and a list containing a number of strings of which one is to be selected, create a function that:

The function should reject input that is not an integer or is out of range by redisplaying the whole menu before asking again for a number. The function should return an empty string if called with an empty list. For test purposes use the following four phrases in a list: This task is fashioned after the action of the Bash select statement.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Menu step by step in the zkl programming language

Source code in the zkl programming language

fcn teleprompter(options){
   os:=T("exit").extend(vm.arglist); N:=os.len();
   if(N==1) return("");
   while(1){
      Utils.zipWith(fcn(n,o){"%d) %s".fmt(n,o).println()},[0..],os);
      a:=ask("Your choice: ");
      try{ n:=a.toInt(); if(0<=n
      println("Ack, not good");
   }
}

teleprompter("fee fie" , "huff and puff" , "mirror mirror" , "tick tock")
.println();

  

You may also check:How to resolve the algorithm Dining philosophers step by step in the BASIC programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the jq programming language
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the Fantom programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the 11l programming language
You may also check:How to resolve the algorithm Longest string challenge step by step in the Run BASIC programming language