![]() 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)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |