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

Help with a loop, print 1-20 to the screen but skips 15, 16, and 17

14
I need help with writing a loop that prints 1-20 to the screen but skips 15, 16, and 17.

I know how to write a for loop that prints any number range, such as 5-200 1-20 etc. But I don't know how to make it skip specific numbers. Please help.

Thanks.
Oct 26 '06 #1
6 2580
arne
315 Expert 100+
I need help with writing a loop that prints 1-20 to the screen but skips 15, 16, and 17.

I know how to write a for loop that prints any number range, such as 5-200 1-20 etc. But I don't know how to make it skip specific numbers. Please help.

Thanks.
Try an 'if'-statement and the 'continue' statement ... :)
Oct 26 '06 #2
JDK721
14
Try an 'if'-statement and the 'continue' statement ... :)
Hmm, i'll try to figure it out.
Oct 26 '06 #3
JDK721
14
This is supposed to be a loop. I didnt think an 'if' statement was a loop, for printing 1-20 I used a for loop.
Oct 26 '06 #4
This is supposed to be a loop. I didnt think an 'if' statement was a loop, for printing 1-20 I used a for loop.
#include <iostream>
using namespace std;

void printNum()//print 1-20 to the screen but skips 15, 16, and 17
{
int x;
for(x=1;x<=20;x++)
{
if( (x ==15) || (x==16) || (x==17))
continue;

cout <<x<<" ";
}

return;
}
int main()
{
printNum();


system("PAUSE");
return 0;
}
Oct 27 '06 #5
JDK721
14
I got it, it was easier than I thought! This is what I wrote, and it worked.

#include <iostream.h>

int main ()
{
int n;

for (n=1; n<21; n++)
{
if (n==15) continue;
if (n==16) continue;
if (n==17) continue;
cout << n << "\n";
}
return 0;
}
Oct 27 '06 #6
Great Stuff.
Oct 27 '06 #7

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

Similar topics

0
by: burn_hall | last post by:
Hi, I have a problem and can't figure it out and need your help, please look at the following code and the output also a xml file snippet is down there too. Looking at the output I don't know why...
15
by: Judi Keplar | last post by:
I am currently taking a course to learn Python and was looking for some help. I need to write a Python statement to print a comma- separated repetition of the word, "Spam", written 511 times...
7
by: mx2k | last post by:
Hello @ all, we have written a small program (code below) for our own in-developement rpg system, which is getting values for 4 RPG-Characters and doing some calculations with it. now we're...
14
by: Bruce W...1 | last post by:
I do a query to MySQL using PHP. Well actually I do too many of them which is the problem, it's too slow. I think maybe an inner join or something would be better but I can't figure this out. ...
4
by: Josh | last post by:
Howdy i am newb somewhat to programing and i was just for fun trying to compile a program that asks the user for an odd int less than 22 and then returns this ***************** ******* *********...
9
by: tym | last post by:
HELP!!! I'm going round the twist with this... I have a VB6 application which is using DAO to access a database (Please - no lectures on ADO, I know what I'm doing with DAO!!) Ok, problem...
2
by: Mark | last post by:
I am trying to export an access 2003 query to XML and need to get it to export in a very specific format. I am stuck and could use some help badly (time is critical with this project). This is...
1
by: roadbai | last post by:
Hi all, This is the first time to post question here, hopefully experts of perl here can give me a hand, to be honest, I am kind of new to perl, and I am struggling with the "Out of memory" issue I...
5
by: sandyw | last post by:
I need help in two areas: Both are at the bottom of my program where a client has two choice to make, 1. When the client enter "Y" it takes him to the begin of the program. I would like to know...
1
by: mshroom12 | last post by:
Hello to all. I am having difficulty trying to do this Java project using Eclipse. The following is what I have to do. Election Day It's almost election day and the election officials need a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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?
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...

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.