CNIT 15501 Lecture Notes - Lecture 8: For Loop, While Loop

58 views2 pages
Loops in C# Notes
Terminology
One Cycle Iteration
Loop Condition
Controls the loop
Loop Variable
Used in the condition
Infinite loop
In Programming
There are 3 main coding structures in high level programming languages:
Sequential
Selection
Repetition
A computer program is a combination of these three coding structures
Repetition Structure
A repetition structure is a segment of code that is executed repeatedly
It is also referred to as loops
Applications:
Compute the annual yield on an investment for 10 years
Read every line from the file until the end of the file is reached
While loop
While is a pretest loop the loop condition is checked at the beginning of each
cycle
Syntax
while ( condition )
{
------
}
For loop
For loop is a pretest loop
For loop is also known as a counting loop.
Use it when number of iterations is known, ex:
Adding numbers 1 to 100.
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

There are 3 main coding structures in high level programming languages: A computer program is a combination of these three coding structures. A repetition structure is a segment of code that is executed repeatedly. Compute the annual yield on an investment for 10 years. Read every line from the file until the end of the file is reached. While is a pretest loop the loop condition is checked at the beginning of each cycle. For loop is also known as a counting loop. Use it when number of iterations is known, ex: Infinite loop int n = 1; int sum = 0; // n++; is missing ---> infinite loop break; statement. Break; can be used inside a for loop or a while loop. Takes the execution to the statement after the loop. Will skip the rest of the current cycle and moves on to the next cycle.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents