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

What's wrong with this code ?

It has to do this

"10...9...8...7...6...5...4...3...2...1...0 BLAST OFF!"

Expand|Select|Wrap|Line Numbers
  1. c.println ("Count Down");
  2. int num = 10;
  3. while (num<10)
  4. {
  5. c.print (num + " . . .");
  6. num = num - 1;
  7. }
  8. c.println ("BLAST OFF!");
It just says
" Count Down
BLAST OFF!"
Feb 10 '08 #1
5 1621
JosAH
11,448 Expert 8TB
It has to do this

"10...9...8...7...6...5...4...3...2...1...0 BLAST OFF!"

Expand|Select|Wrap|Line Numbers
  1. c.println ("Count Down");
  2. int num = 10;
  3. while (num<10)
  4. {
  5. c.print (num + " . . .");
  6. num = num - 1;
  7. }
  8. c.println ("BLAST OFF!");
It just says
" Count Down
BLAST OFF!"
Here's a small question to you: if 'num' equals 10 is it smaller than 10?

kind regards,

Jos
Feb 10 '08 #2
No it's not.... I still don't understand what's wrong with the code though.
Feb 10 '08 #3
Laharl
849 Expert 512MB
Because 10 is not less than 10, you never enter the loop. Also, note that if you change it to <=10, you're going to get an infinite loop.
Feb 10 '08 #4
Just in case:
What is being said is change your statment to

while (num >= 0)

That way it will Count down to 0

The way you have it now basically your statement says;

While (10 < 10)
{
do the stuff in here.
}

Trust me I've done this once or twice myself.... but never a third time tankfully.
Feb 11 '08 #5
Nepomuk
3,112 Expert 2GB
By the way, there's not only one kind of loop - try something similar to this in future:
Expand|Select|Wrap|Line Numbers
  1. for(int i=3; i>=0; i--)
  2. {
  3.    // do something
  4. }
  5.  
(Yes, for-loops can go BOTH ways... ^^)

Greetings,
Nepomuk
Feb 13 '08 #6

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

Similar topics

72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
0
by: sumansms | last post by:
Hi All, I am getting wrong date when I am using DateTime.Parse function. The following is the code.. DateValue = DateTime.Parse(datarow.ToString()).ToString("MM/dd/yyyy"); I am taking the data...
2
maxamis4
by: maxamis4 | last post by:
Hello folks need some ideas here for a report that I am getting together. Here is the scenerio, currently we have an SLA that states that an external group transferring a problem to the internal...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.