L5 Loop While Programming Lecture Notes PDF

Document Details

SaintlySphene5524

Uploaded by SaintlySphene5524

Örebro University

2024

null

Pascal Rebreyend

Tags

programming loops while loops computer science

Summary

This document is a lecture on programming loops, including while loops, do-while loops, and for loops. The lecture was delivered by Pascal Rebreyend on Programming Techniques DT143G. It includes examples and flowcharts.

Full Transcript

Introduction Programmeringsteknik DT143G Lecture 5: Loops Pascal Rebreyend 18-11-2024 Pascal Rebreyend Programmeringsteknik DT143G Introduction Today’s contents While loops Do-while loops For loops...

Introduction Programmeringsteknik DT143G Lecture 5: Loops Pascal Rebreyend 18-11-2024 Pascal Rebreyend Programmeringsteknik DT143G Introduction Today’s contents While loops Do-while loops For loops Nested loops Breaks in a loop Pascal Rebreyend Programmeringsteknik DT143G Introduction Loops Another way to modify and control the flow of instructions Idea: To repeat some instructions for some number of times Some usages: Repeat asking the user if he/she is not entering a valid value Mathematical computations Looping on variables,... to find max,min,average,... going through a table, array (later) Pascal Rebreyend Programmeringsteknik DT143G Introduction While loop while (criteria) statement; or while (criteria){ statement1; statement2;... } Pascal Rebreyend Programmeringsteknik DT143G Introduction Flowchart: While loop Previous statement False criteria? True Statement (body) continue.. Pascal Rebreyend Programmeringsteknik DT143G Introduction While loop #include int main() { int x = 1; while (x!=10) { printf("%d\n",x); x++; } printf("Done\n"); return 0; } Pascal Rebreyend Programmeringsteknik DT143G Introduction Flowchart: Do-While loop Previous statement True Statement (body) criteria? False continue.. Pascal Rebreyend Programmeringsteknik DT143G Introduction Do-While loop #include int main() { int n; do { printf("Enter a number between 10 and 20: "); scanf("%d",&n); } while (!((n>=10) && (n

Use Quizgecko on...
Browser
Browser