![]() ![]() Usage of return and continue statement in a loop %Defining callfunction(), the calling subroutineįunction resultfunc = callfunction(inputval,referenceArray)result=findindex(inputval,referenceArray) if isnan(result)disp('Match is not found.') elsedisp() endendfunctionĬallfunction(-12, )ģ. %Using return statement on achieving the program objectiveįor Index = 1:length(referenceArray) if referenceArray(Index) = inputval return elsedisp('Match not found')endendendfunction ![]() %Using return statement for data validation Index = NaN if inputval< 0 returnend ![]() Returning control to callfunction() from findfunction() return command.Performing validation checking on input data of findindex() function.The below code snippet defines a function findindex() within another function callfunction() where the return command is used with 2 purposes: It can be carried out when its parent subroutine triggers the current in the current subroutine or function, and the command ‘return’ is executed. If the program needs to reroute the flow of control to the calling subroutine or the calling function on the occurrence of some specific condition. Redirecting execution flow to the parent (calling) subroutine from the called subroutine finding matching elementĬase 1: The return statement is executed on a negative input being givenĬase 2: The return statement is executed on match to the input data is foundĢ. %Using return statement on achieving the program objective i.e. %Using return statement for data validation %Defining findindex(), the called subroutineįunction Index = findindex(inputval,referenceArray) Returning control to keyboard once the match is found.Performing validation checking on input data.The below code snippet defines a function findindex() where the return command is used with 2 purposes: If a program needs the user to take action on the occurrence of some specific condition, the current subroutine or function can be called directly without being triggered by any parent sub routine, and the flow of control returns to the command prompt or the keyboard when the command ‘return’ is executed. Some of the important use cases are discussed below. It can also be used for data validity checking functionality. Return command is used in different conditions based on the technical requirement of the program. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |