ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
New problem:Okay I now need to do the same program as below but without using continue. I have no idea how I am supposed to do this, so can someone lead me in the right direction? Thanks!
Old post: I'm having a bit of trouble with the following program I am supposed to make:
Quote:
Write a program to print out a simple counter for odd numbers between 0 and 9, inclusive, using a for loop and a continue statement. The for loop must use a postfix increment of the loop variable (counter++). Add a brief comment at the beginning of the file describing what the program does.
When I compile it in Shell it does not come up with any warnings, but when I try to run it, nothing happens. I've tried changing things around, but no matter what I do, nothing happens when I run the program. Any suggestions? Thanks!
P.S. I'm a beginner at C so if you can keep the programming lingo to a way I can understand it, that would be great!
Last edited by Exsiss; 10-09-2007 at 01:25 AM.
Reason: New Problem
I'm having a bit of trouble with the following program I am supposed to make:
The script I have for it is:
When I compile it in Shell it does not come up with any warnings, but when I try to run it, nothing happens. I've tried changing things around, but no matter what I do, nothing happens when I run the program. Any suggestions? Thanks!
P.S. I'm a beginner at C so if you can keep the programming lingo to a way I can understand it, that would be great!
hi
i think you have given semicolon after if statement... and u wanted to put continue under if condition if i am right... so what is happening, even if the "if " condition is coming it has no effect on continue and continue will execute every time in loop giving no chance for printf 2 print.. so no answer is printed.... remove that semicolon after if statement and run it again...
i think u have given semicolon after "if" statement.. beacuse of which if has no effect on "continue" .. so even if "if" condition happens or not continue executes giving no chance 4 printf to print in whole loop..so nothing is printed remove semicolon after if statement and then execute..
Okay, I'm a little embarrassed to keep asking questions, but I have another question. I edited my original post so that my new problem is there. If someone can help me out with it, that would be great
In C you are not restricted to having a loop increment by just one each time. The i++ can be replaced by i+=3 which will increment the count by three or i*=2 which will double the cunt each time. With that in mind you can simplify your code.
Also, I HIGHLY recommend always using parentheses to delimit if(){...} blocks. Never rely on the implied-next-line-only syntax.
As you have seen, it frequently leads to obscure problems.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.