Using GOTO in ksh to return to already processed code -


i want flow of control go code has been processed . way code ... ... label code ... ... goto label

basically want loop executed again after has been processed once.based on condition

you don't have goto, need implement other flow controls. small example can start after comment main, start normal processing function normal , restart normal when some_condition equals 2.

you can save following script file (gupta.sh), chmod (chmod +x gupta.sh) , call 10 times (./gupta.sh) see different random executions , modify.

#!/bin/ksh  function get_random {    (( between_0_3 = ${random} % 4 ))    echo "random return= ${between_0_3}"    return ${between_0_3} }  function normal {         echo "start normal execution"         get_random         # store return value in var         some_condition=$?         # ksh has switch case keyword         case ${some_condition} in         0)             echo "all went well"             return 0             # syntax in case: finish 2 ; characters             ;;         1)             echo "oops, return error main"             return 1             ;;         2)   echo "this situation want restart (kind-of-goto)."             return 2             ;;         *)   echo "unexpected situation, stop without returning main."             exit 1             ;;         esac }  # main while [ 1 ];    normal    if [ $? -ne 2 ];       break;    fi done echo "end of main" 

this not optimal example of flow control, example how try implement goto. should practice for- , while loops.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -