r/matlab • u/[deleted] • Feb 24 '14
I have this code for checking student grades. Basically I have everything but my one main problem is I can't think of how to rerun the whole loop at the end in case the user wants to check for multiple grades.
3
u/ExoStab Feb 24 '14
I am thinking out loud, but maybe try to use that as a function and then make a while loop. So set a variable that represents the yes or no of checking another grade, and it will repeat the loop as long as that confirmation flag/variable is set.
1
2
u/brntbeer Feb 24 '14
This was killing me, so i created it as a Gist:
https://gist.github.com/brntbeer/d462fe580921d6b4a94e
Feel free to fork it and make edits yourself or hell, just use mine as way to suggest edits by clicking on a line number and grabbing the new URL and saying things like
I can't help but notice on https://gist.github.com/brntbeer/d462fe580921d6b4a94e#file-omar_prieto_problem1-m-L23 that it should possibly be
||not&&
1
u/Day_Old_Pizza Feb 24 '14
Something like this might work:
RUN = true;
while(RUN)
(your code)
quit = input('Do you wish to continue?'); %type 'y' for yes, anything else for no
if(strcmpi(quit,'y'))
RUN = false;
end
end1
0
u/Halsey117 Feb 24 '14
As others have hinted at, look into using a "while" loop outside of what you want to do if the user selects "multiple records". You may also want to prompt the user for their input, so something like:
nrec = input('How many records?');
nrec_start = nrec;
while nrec < 0
% whatever your code to loop over is
nrec = nrec-1;
endBUT: be careful !!! as an improperly parameterized while loop can loop forever.
and i wouldn't be surprised if my code above loops infinitely
5
u/[deleted] Feb 24 '14
Am I the only one who noticed that a text document has been photographed and the picture uploaded? I'm a bit flabbergasted as to the reason why, I must say.