473,387 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Arithmetic using a for loop

heiro1
29
Hello Everyone,
One thing that I was not able to fully understand even though I read through the section on it a few times, is the for loop. I mean, I understand the premise of (statement, condition, update statement). However, I do not quite understand how a math problem is affected by this.

Can someone clarify with a simple example of how this works using multiplication and division? I would really appreciate it!

Oh, and lastly, why would you use a do.. while loop? What is it good for when compared to say, a sentinel loop? Thanks!
Feb 15 '13 #1
1 1467
divideby0
131 128KB
the do while loop test condition is at the bottom and executes at least once. It's useful for user input prompts and waiting for specific values.

Expand|Select|Wrap|Line Numbers
  1. int i = 100;
  2.  
  3. do
  4. {
  5.    cout << i << "\n";
  6.    i += 10;
  7.    // enter loop at least once
  8.  
  9. } while(i <= 100);
  10.  
I'm not sure what you mean by multiplication and division of the for loop. Do you mean the increment and decrement values?

Expand|Select|Wrap|Line Numbers
  1. int i;
  2.  
  3. for(i=1; i <= 100; i *= 10) // mul
  4.    cout << i << "\n";
  5.  
  6. for(i = 100; i >= 1; i /= 10) // div
  7.    cout << i << "\n";
  8.  
Feb 15 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rejimonb | last post by:
Can I fill a combobox without using a loop. Using a loop will be time consuming. Reji
3
by: nico3334 | last post by:
I'm filling in a Report with SQL data using VB code. I'm using LOOP and MoveNext. Before using MoveNext, I would like to be able to check whether the new data is equal to the previous data that was...
1
by: python101 | last post by:
I would like to use loop 'for' to make something look like ------ * * * * * * * * * * #(please don't mind ----- because I can not type the first star in right position) however I...
1
by: bhavanirayala | last post by:
Hi, How can I get the hash values without loop? i.e I want to assign the value of a first key to one variable based on the condition.If that condition falis i need to assign the second value...
5
by: boss1 | last post by:
hi all, i have a problem with loop in select statement.i m using code : <select name = "s" size = "1" > <option selected>P-Code</option> <option...
1
by: xukaifeng | last post by:
Hi guys, I retrieve books from a database and put each book with its data into a bean. this works well, the beans are called bookBeanBeg1, bookBeanBeg2, bookBeanBeg3, bookBeanBeg4, etc. ...
1
by: smepperson | last post by:
Can anyone help explain this in simple terms. My textbok is useless... Have to code a Loop that will check if a name you are adding to a CheckedListBox has already been entered , if not add name...
5
by: dave816 | last post by:
Sorry for the Excel question in an Access forum...................I don't see an Excel forum and there's probably a reason for that but figured I'd give this a shot anyway. Again sorry, delete if...
1
by: Donnie Seibel | last post by:
I wrote a script to list all lines in a file with Perl. I am having trouble with the looping part of it. My script is supposed to look at the file and as long as the file is larger than the current...
0
by: rohit shekhar | last post by:
hi, i have to take 3 property in windows form using 3 textbox.i have to bind arraylist to datagrid.but i have to to show only 2 columns and hide the third one.i use visual studio 2003 and need to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.