Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

cpp class notes for loops

Rating
-
Sold
-
Pages
9
Uploaded on
08-02-2025
Written in
2024/2025

These are the notes of cpp loops which descibe the detail knowledge about loops in cpp.

Institution
Course

Content preview

LOOPS
While loop:

The Power of While Loops in Programming

Imagine you're playing a game where you need to
keep rolling a dice until you get a six. You wouldn't
know in advance how many rolls it would take, but
you'd keep rolling until you reach your goal. This is
similar to how a while loop works in programming.

A while loop is a control structure that allows you to
execute a block of code repeatedly as long as a
certain condition is true. The loop will continue to run
until the condition is met, at which point the loop will
exit.

The Basic Syntax

The basic syntax of a while loop is as follows:

while (condition) {
// code to be executed
}
The condition is a boolean expression that is
evaluated at the beginning of each iteration. If the
condition is true, the code inside the loop will be
executed. If the condition is false, the loop will exit.

Step-by-Step Calculation

, Let's consider an example where we want to print the
numbers from 1 to 5 using a while loop.

let i = 1;
while (i <= 5) {
console.log(i);
i++;
}
Here's how the loop would work:

• i is initialized to 1.
• The condition i <= 5 is evaluated, which is
true.
• The code inside the loop is executed,
printing 1 to the console.
• i is incremented by 1, so i becomes 2.
• Steps 2-4 are repeated until i is greater than
5.
Code Samples

Here are a few more examples of using while loops:

• Printing the numbers from 10 to 1:
let i = 10;
while (i >= 1) {
console.log(i);
i--;
}

Written for

Institution
Course

Document information

Uploaded on
February 8, 2025
Number of pages
9
Written in
2024/2025
Type
Class notes
Professor(s)
Parshottam
Contains
All classes

Subjects

$10.29
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sparshkothari

Get to know the seller

Seller avatar
sparshkothari Lovely professional university
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions