CS 1371 Lecture Notes - Lecture 5: For Loop, Matlab
Document Summary
While loops while expression, statements, end evaluates an expression, and repeats the execution of a group of statements in a loop while the expression is true. An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric). end homework = "cs1371, biol1510, math1502"; assignmentcount = 0; while ~isempty(homework) [class, homework] = strtok(homework, ", "); assignmentcount = assignmentcount + 1; fprintf("\ni have finished d homework. Or, more realistically homework = "cs1371"; homeworkdone = false; while ~homeworkdone fprintf("\nstill working on s",homework); end. For loops repeat a specified amount of time. Now that you did all your homework, you want to see how you did homework = "cs1371, biol1510, math1502"; grade = [60, 92, 44]; curve = [18, 0, 28]; for i = 1:length(grade) [class, homework] = strtok(homework, ", "); score = grade(i) + curve(i); fprintf("s homework grade: d\n",class, score); end. Finds the sum along the major diagonal thesum = 0;