I was trying to make a simple statement with Matlab as follows:
if TF==1
disp('One'), break
else continue
end
... ... ...
... ... ...
But even if TF is not 1, when I run the command, it doesn’t CONTINUE to the rest of the script!! Any help would be appreciated– Thanks
The
continuestatement has a very different meaning. Within a loop, like afororwhileloop,continueinstructs to skip the current round and continue with the next iteration in the loop. So if you removecontinue, you will see the behavior that you are expecting. Here is an example:When the loop iterates at
k == 4, the block calculating the area of the corresponding square is skipped. This particular example is not very practical.However, imagine you have a list of ten file names, and you want to process each file in this loop “
for k = 1 : 10“. You will have to try and open each file, but then if you find out the file does not exist, an appropriate way to handle it would be to print a little warning and thencontinueto the next file.