It depends what language you are using. Structured languages provide the easiest method, simply call the function containing your subroutine and control will automatically return to the point of the call when the function ends. You can even use functions to return a value to the caller. If functions are not an option, the language might provide a gosub statement. This is similar to a goto statement but returns control to the caller, much like a function would in a structured language.
"GOTO" . . . goes to the line number or label indicated, continues program execution from there,forgets where it came from and never looks back."GOSUB" . . . goes to the line number or label indicated and continues program execution from there,but remembers where it came from; as soon as it reaches a "RETURN" command, returns to the commandthat immediately follows "GOSUB".
==== '----------------------------------------------- '*** PROGRAM: Main Menu ' LANGUAGE: QBASIC: VERSION: QB64 '----------------------------------------------- '------------------------------------------ '*** Global variable declarations list... '------------------------------------------ userKeyPress$="" '----------------------- '*** Main Program... '----------------------- DO 'this is a menu driven program... GOSUB clearScreen GOSUB printMainMenuTitleHeading GOSUB printMainMenuOptionsList GOSUB printMainMenuInstructionsHeading GOSUB printMainMenuUserInstructions GOSUB awaitUserKeyPress GOSUB checkUserKeyPress LOOP UNTIL UCASE$(userKeyPress$) = "Q" '...UCASE converts lower case to upper END '...END of program/halt program code execution '---------------------- '*** Sub-routines... '---------------------- clearScreen: CLS '...(CL)ear the output (S)creen RETURN printMainMenuTitleHeading: PRINT "MAIN MENU" PRINT "========" RETURN printMainMenuOptionsList: PRINT "Hit key: <1> for Program 1: 12 X Tables Square" PRINT "Hit key: <2> for Program 2: Select a times tables to print out" PRINT PRINT "Hit key: <Q> to Quit!" PRINT RETURN printMainMenuInstructionsHeading: PRINT "USER INSTRUCTIONS" PRINT "==============" RETURN printMainMenuUserInstructions: PRINT "In order to select from the above Main Menu options list..." PRINT PRINT "First, chose the type of program you wish to run..." PRINT "by, carefully, reading it's description." PRINT PRINT "Then, hit a corresponding single number/letter key, either: '1'/'2';" PRINT "or, alternatively, hit key: 'Q' to Quit!" PRINT PRINT "-Thank you!" RETURN awaitUserKeyPress: DO '...keep looping until when user presses any key... userKeyPress$ = INKEY$ '...store any IN-coming KEY press LOOP UNTIL userKeyPress$ <> "" RETURN checkUserKeyPress: IF userKeyPress$ = "1" THEN GOSUB program1 '...GO to named SUB-routine IF userKeyPress$ = "2" THEN GOSUB program2 '...GO to named SUB-routine RETURN program1: GOSUB clearScreen PRINT "PROGRAM 1" '(...program 1/code goes here...) GOSUB awaitUserKeyPress RETURN program2: GOSUB clearScreen PRINT "PROGRAM 2" '(...program 2/code goes here...) GOSUB awaitUserKeyPress RETURN
IF, in C and C++, is not a function - it is a statement. There are two parameters... if (expression) statement; The expression is evaluated. If it has logical result true, or arithmentic result not zero, the statement is executed; if not, the statement is not executed. The statement can be a single statement, in which it is terminated with a semi-colon, or it can be a block of statements, in which it is surrounded by braces.
Statements are composed from expressions. A semi-colon turns an expression into a statement. A function is not a statement it is a type definition. A statement block is a compound statement, one or more statements delimited by braces, {}. A function block is the body of a function. The body must be enclosed in braces, {}.
It depends what language you are using. Structured languages provide the easiest method, simply call the function containing your subroutine and control will automatically return to the point of the call when the function ends. You can even use functions to return a value to the caller. If functions are not an option, the language might provide a gosub statement. This is similar to a goto statement but returns control to the caller, much like a function would in a structured language.
A function statement is a block where the function is declared and defined.
A function statement is a block where the function is declared and defined.
"GOTO" . . . goes to the line number or label indicated, continues program execution from there,forgets where it came from and never looks back."GOSUB" . . . goes to the line number or label indicated and continues program execution from there,but remembers where it came from; as soon as it reaches a "RETURN" command, returns to the commandthat immediately follows "GOSUB".
==== '----------------------------------------------- '*** PROGRAM: Main Menu ' LANGUAGE: QBASIC: VERSION: QB64 '----------------------------------------------- '------------------------------------------ '*** Global variable declarations list... '------------------------------------------ userKeyPress$="" '----------------------- '*** Main Program... '----------------------- DO 'this is a menu driven program... GOSUB clearScreen GOSUB printMainMenuTitleHeading GOSUB printMainMenuOptionsList GOSUB printMainMenuInstructionsHeading GOSUB printMainMenuUserInstructions GOSUB awaitUserKeyPress GOSUB checkUserKeyPress LOOP UNTIL UCASE$(userKeyPress$) = "Q" '...UCASE converts lower case to upper END '...END of program/halt program code execution '---------------------- '*** Sub-routines... '---------------------- clearScreen: CLS '...(CL)ear the output (S)creen RETURN printMainMenuTitleHeading: PRINT "MAIN MENU" PRINT "========" RETURN printMainMenuOptionsList: PRINT "Hit key: <1> for Program 1: 12 X Tables Square" PRINT "Hit key: <2> for Program 2: Select a times tables to print out" PRINT PRINT "Hit key: <Q> to Quit!" PRINT RETURN printMainMenuInstructionsHeading: PRINT "USER INSTRUCTIONS" PRINT "==============" RETURN printMainMenuUserInstructions: PRINT "In order to select from the above Main Menu options list..." PRINT PRINT "First, chose the type of program you wish to run..." PRINT "by, carefully, reading it's description." PRINT PRINT "Then, hit a corresponding single number/letter key, either: '1'/'2';" PRINT "or, alternatively, hit key: 'Q' to Quit!" PRINT PRINT "-Thank you!" RETURN awaitUserKeyPress: DO '...keep looping until when user presses any key... userKeyPress$ = INKEY$ '...store any IN-coming KEY press LOOP UNTIL userKeyPress$ <> "" RETURN checkUserKeyPress: IF userKeyPress$ = "1" THEN GOSUB program1 '...GO to named SUB-routine IF userKeyPress$ = "2" THEN GOSUB program2 '...GO to named SUB-routine RETURN program1: GOSUB clearScreen PRINT "PROGRAM 1" '(...program 1/code goes here...) GOSUB awaitUserKeyPress RETURN program2: GOSUB clearScreen PRINT "PROGRAM 2" '(...program 2/code goes here...) GOSUB awaitUserKeyPress RETURN
IF function
IF, in C and C++, is not a function - it is a statement. There are two parameters... if (expression) statement; The expression is evaluated. If it has logical result true, or arithmentic result not zero, the statement is executed; if not, the statement is not executed. The statement can be a single statement, in which it is terminated with a semi-colon, or it can be a block of statements, in which it is surrounded by braces.
Statements are composed from expressions. A semi-colon turns an expression into a statement. A function is not a statement it is a type definition. A statement block is a compound statement, one or more statements delimited by braces, {}. A function block is the body of a function. The body must be enclosed in braces, {}.
statement should not return a value but function returns a value
it's not a statement, it's a function: len= printf (format, ...more-parameters...);
All usable statements in PHP can cause a function to be executed - however, that's not to say that every statement will execute a function. A statement is defined by the programmer, who it is ultimately the one responsible for including a function, more than one function, or no functions.
The multi-step income statement is classified by function, and the single-step income statement is classified by behavior.