473,378 Members | 1,475 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,378 software developers and data experts.

Re: Reverse Loop?

On Sat, 17 May 2008 16:36:17 -0700, <msnews.microsoft.comwrote:
[...]
I can't seem to get the for (int i = 80; i <= 50; i++) loop working out
properly. Any advice would be great. Thank you.
Sounds like a homework problem.

Here's a hint: if you want your loop to go backwards, adding to
(incrementing) the counter isn't going to work.

Here's another hint: if you want fractional values, using integers isn't
going to work.

One final hint: in a "for()" statement, the three parts have very broad
rules for usage. The first part is executed once, before the loop begins,
and may contain variable declarations; the second part must simply be some
sort of logical expression that evaluates to a boolean...it can be _any_
expression that meets that requirement; and finally, the third part can be
any statement or statements (separated by commas)...there's nothing that
says it can only be a variable combined with a post-increment operator.

With that information, I think you should be able to rewrite your loop so
that it meets your need.

Pete
Jun 27 '08 #1
1 2041
Love the hints, espectially this one *******. Thats really made my day......

;-D

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sat, 17 May 2008 16:36:17 -0700, <msnews.microsoft.comwrote:
[...]
I can't seem to get the for (int i = 80; i <= 50; i++) loop working out
properly. Any advice would be great. Thank you.
Sounds like a homework problem.

***** Here's a hint: if you want your loop to go backwards, adding to
******
(incrementing) the counter isn't going to work.

Here's another hint: if you want fractional values, using integers isn't
going to work.

One final hint: in a "for()" statement, the three parts have very broad
rules for usage. The first part is executed once, before the loop begins,
and may contain variable declarations; the second part must simply be some
sort of logical expression that evaluates to a boolean...it can be _any_
expression that meets that requirement; and finally, the third part can be
any statement or statements (separated by commas)...there's nothing that
says it can only be a variable combined with a post-increment operator.

With that information, I think you should be able to rewrite your loop so
that it meets your need.

Pete
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
1
by: Marcin Kaliciński | last post by:
template<class RanAccIt> void some_algorithm(RanAccIt begin, RanAccIt end) { // this algorithm involves calling std::lexicographical_compare // on range [begin, end), and on reverse of this range...
3
by: R. Rajesh Jeba Anbiah | last post by:
Unfortunately, I couldn't find any way to traverse the object array in reverse order. I'd thought there must be a way to do it with for..in loop, but couldn't find anything yet. Could someone...
21
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the...
13
by: Aamir Mahmood | last post by:
What could be the fastest method to reverse a string. Speed really matters for my application. Average size of string that comes to my function is around 200K - 300K. Currently i am using the...
41
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
38
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
15
by: Alex Snast | last post by:
Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i)
7
beacon
by: beacon | last post by:
Hi everybody, This may be an easy one, but I'm having a lot of trouble with it. I have a continuous form and I want to validate that the user has entered something in each of the required fields...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.